RadGridView gets empty when I use CollectionViesSource with different inherited classes. Here is the example:
I created following window:
In this example everything is ok, RadGridView and ListView displays same results. In following example everything is ok too:
But if I'll use mixed collection RadGridView become empty and ListBox will display correct results:
Screenshot is attached.
What's the problem here?
I created following window:
<Window x:Class="WpfApplication6.MainWindow"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<CollectionViewSource Source="{Binding Source={x:Static Application.Current}, Path=Employees}" x:Key="employees"/>
</Window.Resources>
<Grid>
<telerik:RadGridView ItemsSource="{Binding Source={StaticResource employees}}" Margin="12,12,0,120" />
<ListBox ItemsSource="{Binding Source={StaticResource employees}}" Margin="12" Height="102" VerticalAlignment="Bottom" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Margin="8" />
<TextBlock Text="{Binding Id}" Margin="8" />
<TextBlock Text="{Binding Class}" Margin="8" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
And codebehind:namespace WpfApplication6{ public partial class App : Application { public ObservableCollection<Employee> Employees { get; set; } private void Application_Startup(object sender, StartupEventArgs e) { Employees = new ObservableCollection<Employee>(); Employees.Add(new Employee() { Name = "Alice", Id = 1 }); Employees.Add(new Employee() { Name = "Bob", Id = 2 }); Employees.Add(new Employee() { Name = "Charlie", Id = 3 }); new MainWindow().Show(); } } public class Employee { public string Name { get; set; } public int Id { get; set; } public virtual string Class { get { return "Base"; } } } public class ExtendedEmployee : Employee { public override string Class { get { return "Extended"; } } }}In this example everything is ok, RadGridView and ListView displays same results. In following example everything is ok too:
Employees.Add(new ExtendedEmployee() { Name = "Alice", Id = 1 });Employees.Add(new ExtendedEmployee() { Name = "Bob", Id = 2 });Employees.Add(new ExtendedEmployee() { Name = "Charlie", Id = 3 });But if I'll use mixed collection RadGridView become empty and ListBox will display correct results:
Employees.Add(new Employee() { Name = "Alice", Id = 1 });Employees.Add(new Employee() { Name = "Bob", Id = 2 });Employees.Add(new ExtendedEmployee() { Name = "Charlie", Id = 3 });Screenshot is attached.
What's the problem here?