0
我將DataGrid
綁定到模型並希望根據數據更改行的顏色。例如,如果模型屬性錯誤是真的。這是我目前有:如何爲MVVM Light應用程序中的DataGrid行着色代碼
<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.
這是什麼[StyleSelectors](http://msdn.microsoft.com/en-us/library/system.windows.controls .styleselector.aspx) –