I am highlighting a grid row based on some Flag property. Something like this:
<Style TargetType="{x:Type igDP:DataRecordPresenter}"> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.Flag}" Value="True"> <Setter Property="FontWeight" Value="Bold" /> </DataTrigger>
Works fine, but if I change the Flag programmatically, the record does not get refreshed.
The underlying object implements INotifyPropertyChanged, and if I show that Flag in a column, the cell value does get changed, but DataTrigger does not work.
Does anybody know a way to refresh the record, make DataTrigger to re-evaluate the condition?
Thanks,Michael
OK, DataTrigger works fine indeed, it was my bug. An interesting one.
The Record.DataItem underlying object implemented INotifyPropertyChanged. So when I received its updated copy, I was refreshing my bound object by copying all field values from the updated one. Using reflection, in a loop through all fields..
Well, it appeared that 'public event PropertyChangedEventHandler PropertyChanged' is also a field, which was nullified in that loop, effectively cutting off all listeners (event handlers), including the DataTrigger.
Michael,
Basically, there are several requirements for this to work:
1. Use a collection that will notify the grid of any changes in it (Observable, BindingList, etc.)
2. You underlying class to implement INotifyPropertyChanged interface.
I have tested this, and it is working correctly (Version 9.1). Make sure that these requirements are correctly fulfilled. If the problem still exists, you can attach a sample project to your next post so that we can look into it (also please mention your dll versions) or contact developer support directly on this link.
Regards,
Alex.
Hi Alex,
> We suggest ObservableCollection<T> or BindingList<T>.
Yes, I use one of them. How would it help? Neither of them has a FireThisParticularRecordChanged() public method. Nor XamDataGrid has a kind of RefreshThisRecord(Record r) method. Or am I missing something?
One more time:
Note: After (3) the object fires PropertyChanged, but nobody seem to care. Otherwise, no changes in the collection have been made, so neither ObservableCollection<T> nor BindingList<T> would fire any event...
Question: Is there a way to "refresh" that record, i.e. make DataTrigger re-calculate the condition and apply the appropriate style prescribed?
(Note: BindingList<T>.ResetBindings() call does the job, by refreshing the entire grid, but it is not acceptible (too slow, loses current record, etc).
Hello Michael,
What is your underlying collection that you are using?
We suggest ObservableCollection<T> or BindingList<T>.