C# 如何更改DataGrid(WPF)中的行背景色?

C# 如何更改DataGrid(WPF)中的行背景色?,c#,wpf,xaml,datagrid,C#,Wpf,Xaml,Datagrid,我需要用某种颜色在DataGrid中绘制一些行 我已在主UI线程中创建集合: ObservableCollection<SomeElement> col= new ObservableCollection<SomeElement> (); 我在SomeElement上实现了INotifyPropertyChanged接口,以便我的DataGrid更新该行中的值。但我想检查此值,并根据它以某种背景色打印行: if (someInputValue > 10) {

我需要用某种颜色在DataGrid中绘制一些行

我已在主UI线程中创建集合:

ObservableCollection<SomeElement> col= new ObservableCollection<SomeElement> ();
我在
SomeElement
上实现了
INotifyPropertyChanged
接口,以便我的
DataGrid
更新该行中的值。但我想检查此值,并根据它以某种背景色打印行:

if (someInputValue > 10) {
    //paint row in some color
}

请告诉我怎么做。谢谢大家的帮助

我自己找到了答案。如果有人感兴趣:

1) 使用XAML中的
CheckProperty
上的
DataTrigger
进行
Binding
。该属性不必是可见的

<Window.Resources>
    <Style TargetType="DataGridRow">
        <Style.Triggers>
            <DataTrigger Binding="{Binding CheckProperty}" Value="Success">
                <Setter Property="Background" Value="Green" />
            </DataTrigger>
            <DataTrigger Binding="{Binding CheckProperty}" Value="Error">
                <Setter Property="Background" Value="Red" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
CheckProperty
必须


当该属性刚刚更新时,
DataTrigger
将被调用,它将根据条件以某种背景颜色打印当前行。

在wpf中,您没有使用
更改/更改
验证模式。而是要验证绑定和相应的属性设置程序(请参阅)。您想解决哪个问题?我需要更新元素的某些属性,并依赖于背景色中的值绘制行。为什么不添加triedI添加的内容,请寻求您的帮助。
int someElementNumber = 1;
int someInputValue = 11;
col[someElementNumber].SomePropery = someInputValue;
if (someInputValue > 10) {
    col[someElementNumber].CheckProperty = "Success";
}
else {
    col[someElementNumber].CheckProperty = "Error";
}
int someElementNumber = 1;
int someInputValue = 11;
col[someElementNumber].SomePropery = someInputValue;
if (someInputValue > 10) {
    col[someElementNumber].CheckProperty = "Success";
}
else {
    col[someElementNumber].CheckProperty = "Error";
}