我将DataGrid
a 绑定到模型并希望根据数据更改行的颜色。例如,如果模型属性错误为真。这是我目前拥有的:
<Grid Name="MyGrid">
<DataGrid ItemsSource="{Binding Path=MyData}">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<Trigger Property="{Binding Path=Error}" Value="true">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Field1" Binding="{Binding Field1}"/>
<DataGridTextColumn Header="Field2" Binding="{Binding Field2}"/>
<DataGridTextColumn Header="Field3" Binding="{Binding Field3}"/>
<DataGridTextColumn Header="Field4" Binding="{Binding Field4}"/>
</DataGrid.Columns>
</DataGrid>
这种方法给了我编译时错误:
A 'Binding' cannot be set on the 'Property' property of type 'Trigger'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.