This is a migrated thread and some comments may be shown as answers.

Property changed event for simple filter

2 Answers 215 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
ianr
Top achievements
Rank 1
ianr asked on 20 Aug 2010, 12:10 PM
Hi,

I am using the datafilter in the mvvm pattern, with the filter collection data stored in the viewmodel, which is then used to build a query to run against a WCF Data Services / OData IQueryable entity.  I'm not connecting the datafilter to another itemscontrol to be populated with ItemProperties, but rather creating my own item properties via reflection and linq off the entity type.

One issue is that I cannot bind to the FilterDescriptors property of the datafilter as it is readonly, so instead I am using a bit of code-behind code to persist this collection between the view and viewmodel when the datacontext changes.

The inability to bind to FilterDescriptors is causing one problem, which is why I am posting here.  I am saving/loading the filter data to/from a database, and would like to know when the data becomes 'dirty' (so that i can indicate visually that the data should be saved).  This is ok for filters being added or removed (via the CollectionChanged event) or for the logical operator being changed (via the PropertyChanged event), but I cannot find any way of detecting when the value of any of the simple filter properties (Member, Operator or MemberValue) have changed.

I've tried adding handlers for all sorts of events on the datafilter and on its viewmodel, but none of the handlers are hit when editing the filters.  I have even looped through the RadDataFilter.ViewModel.CompositeFilter.Filters collection, adding handlers for each item's PropertyChanged event, but still nothing.

So, is there something I can do that I have missed - or - can an event be added when these simple filter values are changed, or can the FilterDescriptors property on the control be made bindable?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 20 Aug 2010, 12:22 PM
Hello ianr,

You can attach to the ItemChanged event of the collection. This event will be fired when a property of a simple filter changes:

this.dataFilter.FilterDescriptors.ItemChanged += this.OnFilterDescriptorsItemChanged;

In the event arguments you will receive the Item (FilterDescriptor) and a PropertyName which indicates what property has changed on the FilterDescriptor, i.e. Member, Value, Operator, etc.

So you can combine both events:

this.dataFilter.FilterDescriptors.CollectionChanged += this.OnFilterDescriptorsCollectionChanged;
this.dataFilter.FilterDescriptors.ItemChanged += this.OnFilterDescriptorsItemChanged;

... and listen for all kinds of changes.

I hope this helps. Let us know if that is not the case.

Greetings,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
ianr
Top achievements
Rank 1
answered on 20 Aug 2010, 12:25 PM
Hi Ross,

Thanks for the (very) fast response.  That's exactly what I was looking for.  I'm not sure how I missed it...

Regards.
Tags
DataFilter
Asked by
ianr
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
ianr
Top achievements
Rank 1
Share this question
or