<UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:Common="clr-namespace:System.Windows;assembly=System.Windows.Controls"
x:Class="SilverlightApplication1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignWidth="640" d:DesignHeight="480"
>
<UserControl.Resources>
<Common:HierarchicalDataTemplate x:Key="TreeNode" ItemsSource="{Binding Path=ChildList}">
<TextBlock Text="{Binding Path=Name}"/>
</Common:HierarchicalDataTemplate>
</UserControl.Resources>
<StackPanel x:Name="LayoutRoot" Loaded="LayoutRoot_Loaded" Orientation="Horizontal">
<controls:TreeView x:Name="myTreeView" ItemTemplate="{StaticResource TreeNode}">
</controls:TreeView>
</StackPanel>
</UserControl>
注:代码是自己在网上找的,就是想记下来方便以后查看
.cs myTreeView.ItemSource = list;//list为数据对象列表
ChildList为数据对象中子列表属性
同样适用的还有TreeGrid哦
来源:https://www.cnblogs.com/codeplace/archive/2012/05/23/2515046.html