Some background:
public class Base
{
public string A { get; set; }
public double B { get; set; }
public DateTime C { get; set; }
public string D { get; set; }
}
public class DerivedClass : Base
{
public string E { get; set; }
public List<string> F { get; set; }
public List<string> G { get; set; }
public Image H { get; set; }
}
The Base class is used as a base for several other classes which all have common properties. The derived classes add on properties specific to that derived class.
In my View I have a DataGrid bound to my DerivedClassViewModel‘s BindingList<DerivedClass>:
<DataGrid Margin="318,0,0,0" ItemsSource="{Binding BindingList}">
This works nicely, I can add and remove items from the BindingList and the DataGrid automatically updates to reflect this. However, DerivedClass has several properties (the List<string> F/H for example) that I don’t want to be displayed in the DataGrid. How do I bind only certain properties of DerivedClass to the DataGrid while still using BindingList<DerivedClass>?
You’ll have to disable AutoGenerateColumns on the DataGrid and define the columns explicitly http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.columns(v=vs.100).aspx, or use the AutoGeneratingColumn event to discard columns you don’t want http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.autogeneratingcolumn(v=vs.100).aspx.