- Define 3
DataTemplates[
^] for each visualization
- Define a
ContentControl[
^] which
Content[
^]-Property is bound to the employee instance.
- Define a
Style[
^] for this
ContentControl[
^]. In this
Style[
^] define
DataTriggers[
^] which examines the EmpDesignation-Property and assign the appropriate
DataTemplate[
^] to the
ContentControls[
^].
ContentTemplate[
^]-Property:
<Window
x:Class="WpfApplication8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication8"
Title="MainWindow"
Height="350"
Width="525">
<Grid>
<Grid.DataContext>
<x:ArrayExtension
Type="local:Employee">
<local:Employee
EmpId="1"
EmpName="EmpName1"
EmpAddress="EmpAddress1"
EmpWorkAppraisal="EmpWorkAppraisal1"
EmpWorkNature="EmpWorkNature1"
EmpDesignation="SeniorManager"></local:Employee>
<local:Employee
EmpId="2"
EmpName="EmpName2"
EmpAddress="EmpAddress2"
EmpWorkAppraisal="EmpWorkAppraisal2"
EmpWorkNature="EmpWorkNature2"
EmpDesignation="AssManager"></local:Employee>
<local:Employee
EmpId="3"
EmpName="EmpName3"
EmpAddress="EmpAddress3"
EmpWorkAppraisal="EmpWorkAppraisal3"
EmpWorkNature="EmpWorkNature3"
EmpDesignation="JuniorManager"></local:Employee>
</x:ArrayExtension>
</Grid.DataContext>
<Grid.Resources>
<DataTemplate
DataType="{x:Type local:Employee}">
<StackPanel Orientation="Horizontal">
<TextBlock
Text="{Binding EmpId}"></TextBlock>
<TextBlock
Text=" - "></TextBlock>
<TextBlock
Text="{Binding EmpName}"></TextBlock>
</StackPanel>
</DataTemplate>
<DataTemplate
x:Key="DT_Employee_SenManager"
DataType="{x:Type local:Employee}">
<StackPanel>
<TextBlock
Text="{Binding EmpId}"></TextBlock>
<TextBlock
Text="{Binding EmpName}"></TextBlock>
<TextBlock
Text="{Binding EmpAddress}"></TextBlock>
</StackPanel>
</DataTemplate>
<DataTemplate
x:Key="DT_Employee_AssManager"
DataType="{x:Type local:Employee}">
<StackPanel>
<TextBlock
Text="{Binding EmpId}"></TextBlock>
<TextBlock
Text="{Binding EmpName}"></TextBlock>
<TextBlock
Text="{Binding EmpWorkNature}"></TextBlock>
</StackPanel>
</DataTemplate>
<DataTemplate
x:Key="DT_Employee_JunManager"
DataType="{x:Type local:Employee}">
<StackPanel>
<TextBlock
Text="{Binding EmpId}"></TextBlock>
<TextBlock
Text="{Binding EmpName}"></TextBlock>
<TextBlock
Text="{Binding EmpWorkAppraisal}"></TextBlock>
</StackPanel>
</DataTemplate>
</Grid.Resources>
<StackPanel>
<ComboBox
Name="_cb"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}">
</ComboBox>
<ContentControl
Content="{Binding /}">
<ContentControl.Style>
<Style
TargetType="ContentControl">
<Style.Triggers>
<DataTrigger
Binding="{Binding EmpDesignation}"
Value="{x:Static local:EmployeeDesignation.SeniorManager}">
<Setter
Property="ContentTemplate"
Value="{StaticResource DT_Employee_SenManager}"></Setter>
</DataTrigger>
<DataTrigger
Binding="{Binding EmpDesignation}"
Value="{x:Static local:EmployeeDesignation.AssManager}">
<Setter
Property="ContentTemplate"
Value="{StaticResource DT_Employee_AssManager}"></Setter>
</DataTrigger>
<DataTrigger
Binding="{Binding EmpDesignation}"
Value="{x:Static local:EmployeeDesignation.JuniorManager}">
<Setter
Property="ContentTemplate"
Value="{StaticResource DT_Employee_JunManager}"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</StackPanel>
</Grid>
</Window>