I have a list of objects implementing INotifyPropertyChange bound to a Grid (particularly CSLA objects). One of the properties is called IsValid and responds true if there is any error on the object.
I've applied the following style
<Style TargetType="{x:Type igDP:DataRecordCellArea}">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.IsValid, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Value="False">
<Setter Property="Background" Value="Red" />
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.IsValid}" Value="True">
<Setter Property="Background" Value="Green" />
</Style.Triggers>
</Style>
I also have a textbox outside of the grid bound to a field of the active record. When I put invalid data in this field, I can see the grid update with the same info, but it doesn't trigger the red background. If I scroll the record out of view and back into view, it then displays a red background. How do I set it up to display the red background when the data becomes invalid?
I believe I am using datatriggers in my example above. What is it I should throw a trigger on? Can you give an example.
Why can't you just use data triggers? They work just fine. The style selector (from what I've deduced) was intended for the initial selection, not to be dynamic.
But again, it's super easy to just throw a trigger on the template where you do anything you want - it's core WPF, just as you'd do with any other control.
This is pretty much a deal breaker for me. I guess I will continue to use the Xceed datagrid until this can get resolved. It's too bad too. I like the feel of this grid better than Xceed.
A while back I tried using the style selector and hit the brick wall. It's not meant to be changed like that (pitty).
You can use data triggers to change the style or the properties.
I'm looking for a solution to an identical problem - i have dynamic styles set on the value editors, with attached converters that output the correct background color. however, the converter gets only called on certain circumstances, like scrolling the grid, ect. ... i also need a way to trigger that manually!
any ideas?