Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

switch items DataTemplate

$
0
0
Say I have the following 2 DataTemplates defined -

    <DataTemplate x:Key="DataTemplateA">
      <StackPanel Orientation="Horizontal">
        <Button>swap</Button>
        <TextBlock Text="this is template a"/>
      </StackPanel>
    </DataTemplate>
   
    <DataTemplate x:Key="DataTemplateB">
      <StackPanel Orientation="Horizontal">
        <Button>swap</Button>
        <TextBlock Text="this is template b"/>
      </StackPanel>
    </DataTemplate>

Is it possible to make the button 'swap' one DataTemplate for another? I want the user to be able to hit a button to change the rendering of an Item in an ItemsControl but I only want to switch that item - not the entire ItemsControl template. Do I need to make a single DataTemplate that internally switches between the 2 modes via a property of the Item itself?



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>