locked
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>
    
    <DataTemplate x:Key="ComplexTemplate">
            <!-- .... -->
    </DataTemplate>
    ...............................
    
    <ItemsControl
           x:Name="MainCanvas" 
           DataContext="{StaticResource mainItems}"
           ItemsSource="{Binding Path=Buttons}"  
           ItemTemplate="{StaticResource SimpleTemplate}"> 
         <ItemsControl.ItemsPanel> 
              <ItemsPanelTemplate>  
                   <Canvas Width="4000" Height="4000" />
              </ItemsPanelTemplate>   
          </ItemsControl.ItemsPanel>
    </ItemsControl> 

    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

Answers

All replies