I have been stuck in the DataGrid styling for hours. I have searched many solutions but to no avail, I haven't been able to apply the styling on my design.
I have this in my View.xaml:
<DataGrid x:Name="dgTransactions"
CanUserAddRows="False"
ColumnHeaderStyle="{StaticResource HeaderStyle}"
ItemsSource="{Binding TransactionLists, Mode=TwoWay}">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding ColorStyle}" Value="Red">
<Setter Property="Background" Value="Red"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ColorStyle}" Value="Blue">
<Setter Property="Background" Value="Blue"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ColorStyle}" Value="Green">
<Setter Property="Background" Value="Green"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
</DataGrid>
What I want to accomplish in this code is that when the ColorStyle value changes, the data row background color also changes depending on what was specified on the DataTrigger but this doesn't seem to work. I do not know what part of my code I should change.
//may it help don't need to code in .cs just in .xaml
//just add your properties in binding let me know if any error
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding _age}" Value="20">
<Setter Property="Background" Value="Red"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding _ismale}" Value="true">
<Setter Property="Background" Value="Green"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>