I have code in the constructor for WPF UserControl. I basically set the binding to XmlDataProvider (my data is dynamic). Then I want to configure CustomSort to represent as MySorter (implementation of IComparer).
The problem is that GetDefaultView returns null if called immediately after calling SetBinding - as if some asynchronous processing is going on to set up the ItemSource. Please note that if I call the same GetDefaultView code later on the Click handler button, it works fine, it does not return null, and the sorting mechanism works fine and dandy.
MyListBox.SetBinding(ListBox.ItemsSourceProperty, binding);
ListCollectionView view = CollectionViewSource.GetDefaultView(MyListBox.ItemsSource) as ListCollectionView;
view.CustomSort = new MySorter(); // falls over - view is null
My question is: why does GetDefaultView return null when called immediately after SetBinding, is there some kind of event that I need to wait before I call GetDefaultView and get a non-zero response?
source
share