Tag: WPF/DataTemplate
<Window x:Class="ControlDemo.OtherDemo.ComboRelatedPane.ComboRelatedPaneWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ComboRelatedPaneWindow" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.Resources>
<DataTemplate x:Key="template1">
<TextBlock>template1</TextBlock></DataTemplate>
<DataTemplate x:Key="template2">
<TextBlock>template2</TextBlock>
</DataTemplate>
</Grid.Resources>
<StackPanel Orientation="Horizontal">
<ComboBox HorizontalAlignment="Left" Width="200"
ItemsSource="{Binding Path=PaneTypes}"
DisplayMemberPath="Label"
SelectedValuePath="Code"
SelectedValue ="{Binding PaneTypeCode}"
/>
</StackPanel>
<ContentControl Grid.Row="1" Content="{Binding}">
<ContentControl.Style>
<Style TargetType="ContentControl">
<Style.Triggers>
<DataTrigger Binding="{Binding PaneTypeCode}" Value="1">
<Setter Property="ContentTemplate" Value="{StaticResource template1}" />
</DataTrigger>
<DataTrigger Binding="{Binding PaneTypeCode}" Value="2">
<Setter Property="ContentTemplate" Value="{StaticResource template2}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</Grid>
</Window>