I have a problem showing items of a special type in a DataGrid
. I created a minimal example.
Let´s say I have an abstract BaseClass
and many inheriting ChildClasses
:
public abstract class BaseClass
{
public int BaseProperty { get; set; }
}
//Many ChildClasses possible
public class ChildClass : BaseClass
{
public int ChildProperty { get; set; }
}
My DataContext contains a collection of all items:
public ObservableCollection<BaseClass> Items { get; set; }
Now I want to show all items of the collection of a special type in a GridView. To filter out a type, I created a CollectionViewSource
:
<CollectionViewSource Source="{Binding Items}" x:Key="ChildClasses" Filter="ChildClassesFilter"/>
And here is the resulting GridView
using the CollectionViewSource
:
<DataGrid ItemsSource="{Binding ChildClasses}"/>
Now my problem:
In the DataGrid
only the BaseProperty
is shown (AutoGenerateColumns
) automatically. How can I force WPF to show also the ChildProperty
without describing the property in the XAML?
Or is there a different approach to show only the items of a special type in my GridView
?