wpf TreeView

<Window x:Class="Mysql.DepartmentParson"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:s="clr-namespace:System.Collections.Generic;assembly=mscorlib"
        xmlns:local="clr-namespace:Mysql.ServiceReference1"
        Title="DepartmentParson" Height="300" Width="300">
    <Grid>
        <TreeView Name="Tree" HorizontalAlignment="Left"  Height="269"  Width="292" >
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Value}">
                    <StackPanel>
                        <TextBlock  Text="{Binding Key.DepartmentName}" Background="Red" />
                    </StackPanel>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <HierarchicalDataTemplate>
                            <TextBlock Text="{Binding Path=ParsonName}"/>
                        </HierarchicalDataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    </Grid>
</Window>
原文地址:https://www.cnblogs.com/zhubaobao/p/3892590.html