2016-12-02 4 views
0

私はダイナミックツリー構造を作成したいと思っています。私はチュートリアルを赤色にしていますが、それは正しくできません。私のwpfツリービューはルート要素のみを表示しています。私は間違って何をしていますか?ここでWPF TreeViewはルート要素のみを表示します

は、メインウィンドウである:ここでは

<Window x:Class="test.MainWindow" 
     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" 
     xmlns:local="clr-namespace:test" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
    <TreeView Name="tv" ItemsSource="{Binding}"> 
     <TreeView.ItemTemplate> 
     <HierarchicalDataTemplate DataType="{x:Type local:Leaf}" 
            ItemsSource="{Binding Childs}">    
      <TextBlock Text="{Binding Path=Name}" /> 
     </HierarchicalDataTemplate> 
     </TreeView.ItemTemplate> 
    </TreeView> 
    </Grid> 
</Window> 

は私のノードクラスは

class Leaf 
{ 
    public string Name { get; set; } 
    public string Address { get; set; } 
    public string Access { get; set; } 
    public string Type { get; set; } 
    public object Value { get; set; } 
    public List<Leaf> Childs; 

    public Leaf() 
    { 
     this.Name = "default"; 
     this.Childs = new List<Leaf>(); 
    } 
} 

public partial class MainWindow : Window 
{ 
    public MainWindow() 
    { 
     InitializeComponent(); 

     List<Leaf> mainlist = new List<Leaf>(); 

     Leaf one = new Leaf(); 
     one.Name = "one"; 

     var two = new Leaf(); 
     two.Name = "two"; 

     one.Childs.Add(two); 

     mainlist.Add(one); 

     tv.DataContext = mainlist; 
    } 
} 

答えて

0

OKですが、リーフスのリストは次のようになりますようだ:

公共一覧チャイルズ{取得する; set;}

問題が解決しました。

関連する問題