Set DataTemplate for a specific item in an ItemsControl RRS feed

  • Question

  • Hi!

    I have an ItemsControl that contains a collection of items that are shown at a page. The ItemsControl has an ItemTemplate property which is set to certain DataTemplate resource.

    <DataTemplate x:Key="SimpleTemplate">
            <!-- .... -->
    <DataTemplate x:Key="ComplexTemplate">
            <!-- .... -->
           DataContext="{StaticResource mainItems}"
           ItemsSource="{Binding Path=Buttons}"  
           ItemTemplate="{StaticResource SimpleTemplate}"> 
                   <Canvas Width="4000" Height="4000" />

    Is it possible to change DataTemplate for a one specific item in my ItemsControl programmatically? I want to change DataTemplate for an item based on property value of that item.

    It seems that ItemsControl in Windows Phone doesn't have ItemTemplateSelector property. So I can't create a template selector class and use it with this control. Any ideas? Is there any way to solve this problem or should I create my own ItemsControl and add ItemTemplateSelector and all needed logic by myself?

    Wednesday, September 25, 2013 12:29 PM


All replies