We use business objects of various types that all implement an interface (IItemData) that provides a few common properties. This allows a single class to build and manage a hierarchical tree of the data bound to the XamGrid just using the interface properties. Unfortunately, the tree is constructed using several ObservableCollection<IItemData> - and, of course, the XamGrid only binds to the properties exposed by the IItemData interface. We use AutoGenerateColumns and supply the ComlumnForamts at runtime.
Is there any event, or other method I can use to cast the business objects back from the IItemData interface to their original class to get the binding working?
Thanks, Steve.
I was so caught up in Binding I didn't think even think of Unbound colums. They work perfectly, even letting us do some runtime data formatting.
Hi,
There isn't an event to allow you to tell us what the actual underlying type of a collection is.
You could cast the collection before you give it to us:
List<IDummyObj> list = new List<IDummyObj>();
for(int i = 0; i < 100; i++) { list.Add(new DummyObj(){ Name=i.ToString(), Age = i}); }
this.grid1.ItemsSource = list.Cast<DummyObj>();
Or, you could just use UnboundColumns, in which we don't actually enforce the column to be of a type in the underlying data.
-SteveZ