Here is what I am trying to do. I have 2 Data Templates defined which both refer to a different user control.
<UserControl.Resources>
<DataTemplate x:Key="myDataTemplate1">
<Border BorderBrush="Black" BorderThickness="1">
<myUserControl1 />
</Border>
</DataTemplate>
<DataTemplate x:Key="myDataTemplate2">
<Border BorderBrush="Black" BorderThickness="1">
<myUserControl2/>
</Border>
</DataTemplate>
</UserControl.Resources>
I am using these Data Templates to display a list of items using ItemsControl like this:
<ItemsControl x:Name="myItemList" ItemTemplate="{StaticResource myDataTemplate1}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate />
</ItemsControl.ItemsPanel>
</ItemsControl>
I would like the ItemTemplate to conditionally be either myDataTemplate1 or myDataTemplate1 depending on the value of an integer variable being 1 or 2 respectively.
Should I use DataTriggers for this or is there another way to do this? Appreciate the help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…