I found a nice solution to show heteogenous data with the help of RowTemplateSelector.I've definied an interface with a merge of the two types involved. Let's see:
public
interface
IData
{
int
MyProperty {
get
;
set
; }
int
MyProperty2 {
get
;
set
; }
int
MyProperty3 {
get
;
set
; }
int
MyProperty4 {
get
;
set
; }
int
MyProperty5 {
get
;
set
; }
string
GroupName {
get
;
set
; }
List<IData> AllChilds {
get
;
set
; }
}
public
class
Group: IData
{
public
Group(List<Group> subGroups, List<Item> items)
{
Subgroups = subGroups;
Items = items;
AllChilds =
new
List<IData>();
AllChilds.AddRange(Subgroups.ToArray());
AllChilds.AddRange(Items.ToArray());
}
public
int
MyProperty {
get
;
set
; }
public
int
MyProperty2 {
get
;
set
; }
public
int
MyProperty3 {
get
;
set
; }
public
int
MyProperty4 {
get
;
set
; }
public
int
MyProperty5 {
get
;
set
; }
public
string
GroupName {
get
;
set
; }
public
List<IData> AllChilds {
get
;
set
; }
public
List<Group> Subgroups {
get
;
set
; }
public
List<Item> Items {
get
;
set
; }
}
public
class
Item: IData
{
public
int
MyProperty {
get
;
set
; }
public
int
MyProperty2 {
get
;
set
; }
public
int
MyProperty3 {
get
;
set
; }
public
int
MyProperty4 {
get
;
set
; }
public
int
MyProperty5 {
get
;
set
; }
public
string
GroupName
{
get
{
return
null
; }
set
{ }
}
public
List<IData> AllChilds
{
get
{
return
null
; }
set
{ }
}
}
public class MyViewModel
{
public List<IData> Children { get; set; }
}
Nou let's use a RadTreeListView in a USerControl
<
UserControl
x:Class
=
"RadControlsSilverlightApp1.MainPage"
xmlns:local
=
"clr-namespace:RadControlsSilverlightApp1"
mc:Ignorable
=
"d"
d:DesignWidth
=
"640"
d:DesignHeight
=
"480"
>
<
UserControl.Resources
>
<
local:MyViewModel
x:Key
=
"ViewModel"
/>
<
local:RowStyleSelector
x:Key
=
"RowStyleSelector"
/>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
DataContext
=
"{StaticResource ViewModel}"
>
<
telerik:RadTreeListView
ItemsSource
=
"{Binding Path=Children}"
RowStyleSelector
=
"{StaticResource RowStyleSelector}"
>
<
telerik:RadTreeListView.ChildTableDefinitions
>
<
telerik:TreeListViewTableDefinition
ItemsSource
=
"{Binding AllChildren}"
/>
</
telerik:RadTreeListView.ChildTableDefinitions
>
<
telerik:RadTreeListView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"MyProperty"
DataMemberBinding
=
"{Binding Path=MyProperty}"
/>
<
telerik:GridViewDataColumn
Header
=
"MyProperty1"
DataMemberBinding
=
"{Binding Path=MyProperty1}"
/>
<
telerik:GridViewDataColumn
Header
=
"MyProperty2"
DataMemberBinding
=
"{Binding Path=MyProperty2}"
/>
<
telerik:GridViewDataColumn
Header
=
"MyProperty3"
DataMemberBinding
=
"{Binding Path=MyProperty3}"
/>
<
telerik:GridViewDataColumn
Header
=
"MyProperty4"
DataMemberBinding
=
"{Binding Path=MyProperty4}"
/>
<
telerik:GridViewDataColumn
Header
=
"MyProperty5"
DataMemberBinding
=
"{Binding Path=MyProperty5}"
/>
</
telerik:RadTreeListView.Columns
>
</
telerik:RadTreeListView
>
</
Grid
>
</
UserControl
>
Note that ItemsSource is a List<IData>, and TreeListViewTableDefinition has as itemsSource the AllChildren property definied in IData.
A RowStyleSelecor is needed, it looks as following:
Easy selector, I want rows with Group instances to look without cells, just a TextBlock with the GroupName. So I must provide a GroupRowStyle an modify the RowTemplate. As all you know, the GridViewRowTemplate has a lot of xaml, the best option is, using blend, editing the RadTreeListView RowStyle. What I did was editing the RowStyle at the App.xaml (so it's avaliable via Application.Resources) with a "GroupRowStyle" key. I won't copy all the xaml, is a lot of code. Jus the key to not show the cells is substitute the DataCellsPresenter named "PART_DataCellsPresenter" by a ContentPresenter as follows:
Easy, now, rows with Group instances will not show cells, just the GroupName. Of course, a more xaml work is neede to give the "GroupRowStyle" a nice look.
I0d like to attach the example solution, but zip o rar are not allowed types.