If I try to set the column group descriptor to null, inside of the collections changing event for the grid group descriptors collection, the UI crashes as well.
I have a small project that will reproduce the problem, but I see I am unable to attach it. The code excerpts are below.
Thanks,
Tom
Code:
public MainPage()
{
this.InitializeComponent();
this.DataGrid.ItemsSource = new List<Data>
{
new Data { Name = "Mario", Hobby = "Boxing", Age = 22 },
new Data { Name = "Smith", Hobby = "Skating", Age = 23 },
new Data { Name = "Maya", Hobby = "Swimming", Age = 24 },
new Data { Name = "Sonya", Hobby = "Jogging", Age = 21 },
new Data { Name = "Tom", Hobby = "Jogging", Age = 25 },
new Data { Name = "Mario", Hobby = "Skating", Age = 22 },
new Data { Name = "Smith", Hobby = "Skating", Age = 25 },
new Data { Name = "Peter", Hobby = "Boxing", Age = 22 },
new Data { Name = "Lorenzo", Hobby = "Boxing", Age = 24 }
};
this.DataGrid.GroupDescriptors.CollectionChanged += GroupDescriptors_CollectionChanged;
}
void GroupDescriptors_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
DataGridTemplateColumn ageColumn = FindAgeColumn() as DataGridTemplateColumn;
if (ageColumn == null) return;
if (e.NewItems != null)
{
// This line of code blows UI up
//ageColumn.GroupDescriptor = null;
}
if (e.OldItems != null)
{
ageColumn.GroupDescriptor = e.OldItems[0] as GroupDescriptorBase;
}
}
DataGridColumn FindAgeColumn()
{
foreach (DataGridColumn column in this.DataGrid.Columns)
{
if (column.Header.ToString() == "Age")
return column;
}
return null;
}
<telerikGrid:RadDataGrid x:Name="DataGrid" AutoGenerateColumns="False" >
<telerikGrid:RadDataGrid.GroupDescriptors>
<telerikGrid:DelegateGroupDescriptor x:Name="ageGroupDescriptor" >
<telerikGrid:DelegateGroupDescriptor.KeyLookup>
<local:CustomIKeyLookup/>
</telerikGrid:DelegateGroupDescriptor.KeyLookup>
</telerikGrid:DelegateGroupDescriptor>
</telerikGrid:RadDataGrid.GroupDescriptors>
<telerikGrid:RadDataGrid.Columns>
<telerikGrid:DataGridTemplateColumn Header="Name">
<telerikGrid:DataGridTemplateColumn.CellContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DataTemplate>
</telerikGrid:DataGridTemplateColumn.CellContentTemplate>
</telerikGrid:DataGridTemplateColumn>
<telerikGrid:DataGridTemplateColumn Header="Hobby">
<telerikGrid:DataGridTemplateColumn.CellContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding Hobby}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DataTemplate>
</telerikGrid:DataGridTemplateColumn.CellContentTemplate>
</telerikGrid:DataGridTemplateColumn>
<telerikGrid:DataGridTemplateColumn Header="Age" x:Name="ageColumn">
<telerikGrid:DataGridTemplateColumn.CellContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding Age}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DataTemplate>
</telerikGrid:DataGridTemplateColumn.CellContentTemplate>
</telerikGrid:DataGridTemplateColumn>
</telerikGrid:RadDataGrid.Columns>
</telerikGrid:RadDataGrid>
public class CustomIKeyLookup : IKeyLookup
{
public object GetKey(object instance)
{
return (instance as Data).Age;
}
}