使用DataTrigger设置DataGridCell背景 [英] Setting DataGridCell Background with DataTrigger

查看:201
本文介绍了使用DataTrigger设置DataGridCell背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁能告诉我为什么以下XAML代码中的DataTriggers设置DataGrid整行的背景颜色而不是单个单元格?我将TargetType设置为DataGridCell。



Can anyone tell me why the DataTriggers in the following XAML code are setting the background color of the entire row of the DataGrid and not the individual cell? I have the TargetType set to "DataGridCell".

<pre lang="xml"><DataGrid>
            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=aciton}" Value="ADDED">
                            <Setter Property="Background" Value="LightGreen"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=aciton}" Value="UPDATED">
                            <Setter Property="Background" Value="LightBlue"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=aciton}" Value="REMOVED">
                            <Setter Property="Background" Value="Salmon"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.CellStyle>
        </DataGrid>

推荐答案

我怀疑行中的每个单元格可能都在查看相同的属性 aciton 。因此,当 aciton 的值发生变化时,该行中的每个单元格都会获得相同的颜色。
I would suspect that every cell in the row probably is looking at the same property aciton. Therefore when the value of aciton changes, every cell in the row gets the same color.


这篇关于使用DataTrigger设置DataGridCell背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆