Property changed event for simple filter

3 posts, 0 answers
  1. ianr
    ianr avatar
    14 posts
    Member since:
    Mar 2010

    Posted 20 Aug 2010 Link to this post


    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?

  2. Rossen Hristov
    Rossen Hristov avatar
    2478 posts

    Posted 20 Aug 2010 Link to this post

    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.

    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
  3. DevCraft R3 2016 release webinar banner
  4. ianr
    ianr avatar
    14 posts
    Member since:
    Mar 2010

    Posted 20 Aug 2010 Link to this post

    Hi Ross,

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

Back to Top