I'm trying to display different templates based on amount of items in observable collection.
I have done the following
My XAML looks like:
This throws me XML parsing exception. I tried binding observable collection directly and doing count on selector side as well, however it hasn't made any difference. Is there any way of implementing this behaviour with template selector or am I wasting my time?
Thanks!
I have done the following
public class SplitTemplateSelector : DataTemplateSelector
{
private int _count;
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (Count == 1)
{
return SingleSplitTemplate;
}
else if (Count > 0)
{
return MultiSplitTemplate;
}
return null;
}
public DataTemplate SingleSplitTemplate
{
get;
set;
}
public DataTemplate MultiSplitTemplate
{
get;
set;
}
public int Count { set; get; }
}
My XAML looks like:
<
telerik:ItemsControl
ItemsSource
=
"{Binding OriginatingIdtSplits}"
VerticalAlignment
=
"Stretch"
HorizontalAlignment
=
"Stretch"
>
<
telerik:ItemsControl.ItemTemplateSelector
>
<
local:SplitTemplateSelector
SingleSplitTemplate
=
"{StaticResource SingleSplitTemplate}"
MultiSplitTemplate
=
"{StaticResource MultiSplitTemplate}"
Count
=
"{Binding OriginatingIdtSplits.Count}"
/>
</
telerik:ItemsControl.ItemTemplateSelector
>
<
ItemsPanelTemplate
>
<
StackPanel
Orientation
=
"Horizontal"
MinWidth
=
"400"
/>
</
ItemsPanelTemplate
>
</
telerik:ItemsControl
>
This throws me XML parsing exception. I tried binding observable collection directly and doing count on selector side as well, however it hasn't made any difference. Is there any way of implementing this behaviour with template selector or am I wasting my time?
Thanks!