在我的XAML代码中,我希望根据特定行中对象的值来设置每行的Background
颜色。我有一个z
的ObservableCollection
,每个z
都有一个名为State
的属性。我一开始在我的DataGrid
中有类似这样的东西
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background"
Value="{Binding z.StateId, Converter={StaticResource StateIdToColorConverter}}"/>
</Style>
</DataGrid.RowStyle>
这是一个错误的方法,因为x不是我的ViewModel类中的一个属性。
在我的ViewModel类中,我有一个ObservableCollection<z>
,它是这个DataGrid
的ItemsSource
,还有一个z
类型的SelectedItem
。
我可以将颜色绑定到SelectedItem
,但这只会更改DataGrid
中的一行。
如何根据一个属性更改此行的背景颜色?
https://stackoverflow.com/questions/18053281
复制相似问题