I want the background color of a WPF datagrid cell to change color when the content has been changed. Each cell has a ViewModel object that contains the following properties: Value, OriginalValue, and Modified. When the user edits the contents of the cell, this automatically calls the Amount property by means of data binding. Then this property installer checks it for the initial value and sets the boolean Modified property to true or false, respectively, notifies the bindings for these properties for updating.
I have so far achieved a partial result with a style in the ElementStyle property for a DataGridTextColumn as follows
<Style x:Key="DataGridTextStyle" TargetType="{x:Type TextBlock}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=MyViewModel.Modified}" Value="True"> <Setter Property="Background" Value="Yellow"/> </DataTrigger> </Style.Triggers> </Style>
This updates the background color of the text content, but it is only a small area in the center of the cell. I want the whole cell to update its background color, and not just the textblock attribute.
Can I change the trigger above to search up in the visual tree to find the parent DataGridCell and set the Background property for it, and not set only the background color of the current text block?
c # css wpf datagrid
Nzjames
source share