0

I have a treeview inside of a dockpanel and all of the elements of the treeview are inside HierarchicalDataTemplates. Here is the code:

<DockPanel Margin="10,10,0,0" VerticalAlignment="Stretch" Grid.Row="0" Grid.RowSpan="5" Grid.Column="0">
        <DockPanel.Resources>

            <src:TreeViewFilter x:Key="MyList" />

            <HierarchicalDataTemplate DataType="{x:Type src:TreeViewParent}" ItemsSource="{Binding Path=OrderAttributes}">
                <TextBlock Text="{Binding Path=Name}" FontSize="24"/>
            </HierarchicalDataTemplate>

            <HierarchicalDataTemplate DataType="{x:Type src:OrderAttribute}" ItemsSource="{Binding Path=OrderAttributes}">
                <TextBlock Text="{Binding Path=NameAndCount}" FontSize="16"/>
            </HierarchicalDataTemplate>

        </DockPanel.Resources>
        <TreeView Name="treeView1" BorderThickness="2" ItemsSource="{Binding Source={StaticResource MyList}, UpdateSourceTrigger=PropertyChanged}" TreeViewItem.Selected="treeViewFilter"/>
    </DockPanel>

As you can see, the DockPanel wraps around the TreeView. The icons I am trying to add would be in the second HierarchicalDataTemplate which binds to a string and displays as a textbox. Depending on the name of the "NameAndCount", I would choose an icon to be displayed next to it on the left.

Any ideas on a solution for my example? Or do I need to think about using different templates like StackPanel?

Kevin Quiring
  • 639
  • 1
  • 11
  • 26

1 Answers1

0

Add an Image-Control wherever you want, bind its Source to "NameAndCount" and use a IValueConverter to convert it to an image-path.

Florian Gl
  • 5,984
  • 2
  • 17
  • 30