I was working on a proof of concept for binding to an ObservableCollection property which returns the result of a delegate. The delegate has a property set up for it also, so that I can change the expression used, and it triggers OnPropertyChanged for the Collection. This allows me to bind a ComboBox to the Collection, and upon changing the expression/query the available choices in the ComboBox will change too.
Code:
public delegate List<string> Del(); private Del _query; public Del Query { get { return _query; } set { _query= value; OnPropertyChanged("BindList"); } } private ObservableCollection<string> bindList; public ObservableCollection<string> BindList { get { var results = Query(); bindList = new ObservableCollection<string>(results); return bindList; } set {//I believe I need this setter for the extra functionality provided by ObservableCollections over Lists if(bindList != value) { bindList = value; OnPropertyChanged("BindList"); } } } Since this works, I'm wanting to make a class out of it that will be simple to bind to. I'm asking for guidance on how to do so. I've thought some about subclassing ObservableCollection, but was having issues with how to set the Items. I've also considered just a custom class using interfaces like IEnumerable and ICollectionView (along with the notification Interfaces).
So in summary, how would you build a class to incorporate a collection whose members are based on a delegate query (LINQ to be specific) with regard to subclassing/interfaces?
Thanks in advance.
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog