zoukankan      html  css  js  c++  java
  • WPF 改变Datagrid的选中行的颜色

    主要通过设置DataGrid的RowStyle和CellStyle即可。

                 <Style TargetType="DataGridRow" x:Key="gridRowStyle">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" Value="LightGray"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
    
                <Style TargetType="DataGridCell" x:Key="gridCellStyle">
                    <!--文字居中-->
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type DataGridCell}">
                                <Grid Background="{TemplateBinding Background}">
                                    <ContentPresenter HorizontalAlignment="Center" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <!--被选中时,背景色改变-->
                    <Style.Triggers>
                        <Trigger Property="DataGridCell.IsSelected" Value="True">
                            <Setter Property="Background" Value="Gray" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
           <DataGrid ScrollViewer.CanContentScroll="False" AutoGenerateColumns="False" CanUserAddRows="False"
                 CellStyle="{StaticResource gridCellStyle}"
                          RowStyle="{StaticResource gridRowStyle}" />
  • 相关阅读:
    约数
    质数
    回炉重造之重读Windows核心编程-018-堆栈
    回炉重造之重读Windows核心编程-017- 内存映射文件
    换电脑遇到git的一些记录
    python3之迭代器和生成器
    python3之类和对象
    python3之错误和异常
    python3之函数
    python3之流程控制
  • 原文地址:https://www.cnblogs.com/hbatjzyb/p/9370078.html
Copyright © 2011-2022 走看看