C# 如何更改/设置datagrid中单行的背景色?
如何使用c#?尝试将项模板的背景属性绑定到数据项的属性,以更改数据网格中单行的背景颜色。上面的代码用于列表项模板:C# 如何更改/设置datagrid中单行的背景色?,c#,wpf,xaml,datagrid,C#,Wpf,Xaml,Datagrid,如何使用c#?尝试将项模板的背景属性绑定到数据项的属性,以更改数据网格中单行的背景颜色。上面的代码用于列表项模板: XAML ... 尝试以下代码: XAML: 条件格式?例如: <Window.Resources> <Style TargetType="DataGridRow"> <Style.Triggers> <DataTrigger Binding="{Binding Property }" Val
XAML
...
尝试以下代码:
XAML:
条件格式?例如:
<Window.Resources>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Property }" Value="True">
<Setter Property="Background" Value="#FAFAFA" />
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
private void MarkRowAsDone(object sender, MouseButtonEventArgs e)
{
using (var context = new Context())
{
try
{
//If you have set a ID, get that ID to do a "select"-statement
var row = context.CLASS.Find(selectedItem.Id);
row.Done = true;
context.SaveChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}