c# - WPF: Manipulating DataGrid binding in ViewModel -


lets consider 3 classes following:

public class animal {     public string name { set; get; }     public string genome { set; get; } } public class car {     public string name { set; get; }     public int model { set; get; }     public int horsepower { set; get; } } public class tree {     public string name { set; get; }     public int age { set; get; } } 

and collection of each type following:

    observablecollection<animal> animals { set; get; }     observablecollection<car> cars { set; get; }     observablecollection<tree> trees { set; get; } 

we have combobox it's items animals, cars, , trees. based on user's selection each of these collections displayed in datagrid. however, since data types different, not possible define proper binding of column in advance, , bindings has changed respect combobox selection. have suggestions on how address scenario ?

assumptions:

  • we're in mvvm pattern.
  • we don't wanna have 1 datagrid each type (summing 3 datagrids in total).
  • we're not allowed modify models.

if dont want multiple datagrids, go single datagrid columns object types. @ runtime you'll hide columns not related current type. btw it's not different having multiple datagrids , hide not related current type.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -