2

I've got a KeyValuePair. At first i've bound only the Value Part to my TreeView in my Datatemplate. In this case, the Binding doesn't work correctly, but the hierachial template is choosen correct.

Is there a way to chose the correct Datatemplate via DataType syntax for a KeyValuePair?

Used TreeView:

<TreeView  Margin="5" Grid.RowSpan="2" Grid.Row="0" Name="tvw_mainMenu" Style="    {DynamicResource NavigationTree}" ItemsSource="{Binding Values}"/>

DataContext (Code behind):

mainwindow.DataContext = _myObservableDictionary;

Used Templates:

<HierarchicalDataTemplate DataType="{x:Type local:Scanners}" ItemsSource="{Binding Values}">
    <TextBlock Text="Scanner" FontStyle="Italic"/>
</HierarchicalDataTemplate>

<HierarchicalDataTemplate DataType="{x:Type local:Scanner}">
    <StackPanel Orientation="Horizontal">
        <Image Width="16" Height="16" Margin="3,0" Source="/Resources/Icons/scanner.png" />
        <TextBlock Text="{Binding SourceName}" FontStyle="Italic"/>
    </StackPanel>
</HierarchicalDataTemplate>

<HierarchicalDataTemplate DataType="{x:Type local:FieldInformations}" ItemsSource="{Binding Values}">
    <TextBlock Text="Felder" FontStyle="Italic"/>
</HierarchicalDataTemplate>

<HierarchicalDataTemplate DataType="{x:Type local:FieldInformation}">
    <StackPanel Orientation="Horizontal">
        <Image Width="16" Height="16" Margin="3,0" Source="/Resources/Icons/textfield.png" />
        <TextBlock Text="{Binding Caption}" FontStyle="Italic"/>
    </StackPanel>
</HierarchicalDataTemplate>

<HierarchicalDataTemplate DataType="{x:Type local:Sheets}" ItemsSource="{Binding Values}">
    <TextBlock Text="Seiten" FontStyle="Italic"/>
</HierarchicalDataTemplate>

<HierarchicalDataTemplate DataType="{x:Type local:Sheet}">
    <StackPanel Orientation="Horizontal">
        <Image Width="16" Height="16" Margin="3,0" Source="/Resources/Icons/page_green.png" />
        <TextBlock FontStyle="Italic"/>
    </StackPanel>
</HierarchicalDataTemplate>
Lif3styl3
  • 63
  • 2
  • 9

0 Answers0