Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
410
XamGrid Binding Objects Implementing Interfaces
posted

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.

Parents
  • 40030
    Offline posted

    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

Reply Children
No Data