//更改表格的标题行样式 ..._wpf datagrid 根据 d">
当前位置:   article > 正文

WPF通过MultiDataTrigger触发器来动态更改表格(DataGrid)的样式_wpf datagrid 根据 datatrigger 显示多种行模板

wpf datagrid 根据 datatrigger 显示多种行模板

为了防止自己忘记,加深记忆。

     <ControlLibrary:DataGridEx x:Name="dgTable" HorizontalAlignment="Stretch"  
                                        Style="{DynamicResource DataGridStyle}" >
                <DataGrid.ColumnHeaderStyle>//更改表格的标题行样式
                    <Style TargetType="DataGridColumnHeader">
                        <Setter Property="HorizontalContentAlignment" Value="Center" ></Setter>//居中
                        <Setter Property="FontSize" Value="15"></Setter>//字体大小
                        <Setter Property="Foreground" Value="#FFEBF5F5"></Setter>
                        <Setter Property="Background" Value="#FF326DD4"></Setter>
                    </Style>
                </DataGrid.ColumnHeaderStyle>
                <DataGrid.Columns>

                    <DataGridTextColumn x:Name="columnHeader1" CanUserSort="False" Header="电池编号"   Binding="{Binding BatteryOrder}" ElementStyle="{StaticResource DataGridTextCenter}" Width="*" >

                    </DataGridTextColumn>
                    <DataGridTextColumn x:Name="columnHeader2" CanUserSort="False" Header="开始电压" Binding="{Binding StartVoltage}" ElementStyle="{StaticResource DataGridTextCenter}" Width="*"/>
                    <DataGridTextColumn x:Name="columnHeader3" CanUserSort="False" Header="终止电压" Binding="{Binding EndVoltage}" ElementStyle="{StaticResource DataGridTextCenter}" Width="*"/>
                    <DataGridTextColumn x:Name="columnHeader4" CanUserSort="False" Header="电池内阻/mΩ" Binding="{Binding BatteryResistance}" ElementStyle="{StaticResource DataGridTextCenter}" Width="*"/>
                    <!--<DataGridTextColumn x:Name="columnHeader5" CanUserSort="False" Header="实验结论" Binding="{Binding TestResult}" ElementStyle="{StaticResource DataGridTextCenter}"/>-->
                    <!--<DataGridTextColumn  Width="100" Header="维护方案" Binding="{Binding Maintenance}"/>-->

                    <DataGridTextColumn x:Name="columnHeader5" CanUserSort="False" CanUserReorder="False" Header="实验结论" ElementStyle="{StaticResource DataGridTextCenter}" Width="*" >

                        <DataGridTextColumn.Binding>
                            <MultiBinding Converter="{StaticResource ResourceKey=DataReportTestResultConverter}">
                                <Binding Path="StartVoltage"/>
                                <Binding Path="EndVoltage"/>
                                <Binding Path="dicLanguages"/>
                            </MultiBinding>
                        </DataGridTextColumn.Binding>
                    </DataGridTextColumn>

                    <DataGridTextColumn x:Name="columnHeader6" CanUserSort="False" CanUserReorder="False" Header="维护方案" ElementStyle="{StaticResource DataGridTextCenter}" Width="*">
                        <DataGridTextColumn.Binding>
                            <MultiBinding Converter="{StaticResource ResourceKey=DataReportMaintenanceConverter}">
                                <Binding Path="StartVoltage"/>
                                <Binding Path="EndVoltage"/>
                            </MultiBinding>
                        </DataGridTextColumn.Binding>
                    </DataGridTextColumn>
                </DataGrid.Columns>
                <DataGrid.CellStyle> //更改行的样式
                    <Style TargetType="{x:Type DataGridCell}">
                    //去掉单元格中间的竖线
                        <Style.Triggers>
                         <Trigger Property="IsSelected" Value="False">
                                <Setter Property="BorderThickness" Value="0"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="BorderThickness" Value="0"/>
                            </Trigger>
                                //根据数据源中TestResult列的的内容来显示相应的颜色    正常电池就是Orange  严重就是Red
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding TestResult}" Value=" 正常电池"/>
                                </MultiDataTrigger.Conditions>
                                <MultiDataTrigger.Setters>
                                    <Setter Property="Background" Value="Orange"/>
                                </MultiDataTrigger.Setters>
                            </MultiDataTrigger>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding TestResult}" Value="严重劣化电池"/>
                                </MultiDataTrigger.Conditions>
                                <MultiDataTrigger.Setters>
                                    <Setter Property="Background" Value="red"/>
                                </MultiDataTrigger.Setters>
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.CellStyle>
            </ControlLibrary:DataGridEx>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/582835
推荐阅读
相关标签