In my XAML code, I want to set the Background
color of each row, based on a value of the object in one specific row. I have an ObservableCollection
of z
, and each of the z
has a property called State
. I started out with something like this in my DataGrid
:
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background"
Value="{Binding z.StateId, Converter={StaticResource StateIdToColorConverter}}"/>
</Style>
</DataGrid.RowStyle>
This is a wrong approach because x is not a property in my ViewModel class.
In my ViewModel class I have an ObservableCollection<z>
which is the ItemsSource
of this DataGrid
, and a SelectedItem
of type z
.
I could bind the color to SelectedItem
, but this will only change one row in the DataGrid
.
How can I, based on one property change this rows backgroundcolor?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…