Hi,
can someone tell me how to make the following sample work (grouping by inner ID fails) without modifying the OuterElement-class (in real world that comes from a third-party)?
The problem seems to be that the grouping does not use the right runtime-type but the type of the property(which is an interface that is inherited by SpecialInnerElement). Have a look and you see what I mean.
xaml:
code-behind:
Best Regards
Steffen
can someone tell me how to make the following sample work (grouping by inner ID fails) without modifying the OuterElement-class (in real world that comes from a third-party)?
The problem seems to be that the grouping does not use the right runtime-type but the type of the property(which is an interface that is inherited by SpecialInnerElement). Have a look and you see what I mean.
xaml:
<Window x:Class="RadGridGroupingType.Window1" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" |
xmlns:telerikdata="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data" |
xmlns:sys="clr-namespace:System;assembly=mscorlib" |
Title="Window1" Height="300" Width="300"> |
<Grid> |
<telerik:RadGridView Name="radgv" AutoGenerateColumns="False" ItemsSource="{Binding}"> |
<telerik:RadGridView.Columns> |
<telerik:GridViewDataColumn Header="outer ID" DataType="{x:Type sys:Int32}" GroupMemberPath="ID"> |
<telerik:GridViewColumn.CellTemplate> |
<DataTemplate> |
<TextBlock Text="{Binding Path=ID}"/> |
</DataTemplate> |
</telerik:GridViewColumn.CellTemplate> |
</telerik:GridViewDataColumn> |
<telerik:GridViewDataColumn Header="inner ID" DataType="{x:Type sys:Int32}" GroupMemberPath="InnerElement.ID"> |
<telerik:GridViewColumn.CellTemplate> |
<DataTemplate> |
<TextBlock Text="{Binding Path=InnerElement.ID}"/> |
</DataTemplate> |
</telerik:GridViewColumn.CellTemplate> |
</telerik:GridViewDataColumn> |
</telerik:RadGridView.Columns> |
</telerik:RadGridView> |
</Grid> |
</Window> |
code-behind:
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Text; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Data; |
using System.Windows.Documents; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Imaging; |
using System.Windows.Navigation; |
using System.Windows.Shapes; |
using System.Collections.ObjectModel; |
namespace RadGridGroupingType |
{ |
/// <summary> |
/// Interaction logic for Window1.xaml |
/// </summary> |
public partial class Window1 : Window |
{ |
public Window1() |
{ |
InitializeComponent(); |
ObservableCollection<OuterElement> col = new ObservableCollection<OuterElement>(); |
col.Add(new OuterElement() { ID = 1 }); |
col.Add(new OuterElement() { ID = 2 }); |
col.Add(new OuterElement() { ID = 3 }); |
radgv.DataContext = col; |
} |
} |
public class OuterElement |
{ |
public int ID { get; set; } |
private SpecialInnerElement m_innerElement = new SpecialInnerElement() { ID = 99 }; |
//public SpecialInnerElement InnerElement //returning the right runtimeType: grouping works |
public IInnerElement InnerElement //returning interface: grouping does not work |
{ |
get { return m_innerElement; } |
} |
} |
public interface IInnerElement |
{ |
//"does not matter"; |
} |
public class SpecialInnerElement: IInnerElement |
{ |
public int ID { get; set; } |
} |
} |
Best Regards
Steffen