2017-03-06 4 views
0

私はWPFに新しく、リストのリストなどにバインドされたツリービューの作成に悩まされています。必要に応じて子ノードの数を増やすことができます。私は、コードをオフにテストするために2 HierarchicalDataTemplatesを作成しますが、子ノードがリストのリストのリストへのツリービューのデータバインド

マイツリービューが

<telerik:RadTabItem Header="Lookup Sets"> 
    <telerik:RadTreeView IsLoadOnDemandEnabled="True" ItemsSource="{Binding AttributeLookupSetConversions}"> 
     <telerik:RadTreeView.Resources> 
      <HierarchicalDataTemplate DataType="{x:Type cm:AttributeLookupSetConversion}"> 
       <CheckBox Content="{Binding Path=Name}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerikDocking:RadSplitContainer}}, Path=DataContext.UpdateSelectionCommand}"/> 
      </HierarchicalDataTemplate> 
      <HierarchicalDataTemplate DataType="{x:Type cm:AttributeConversion}"> 
       <CheckBox Content="{Binding Path=Name}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerikDocking:RadSplitContainer}}, Path=DataContext.UpdateSelectionCommand}"/> 
      </HierarchicalDataTemplate> 
     </telerik:RadTreeView.Resources> 
    </telerik:RadTreeView> 
</telerik:RadTabItem> 

として定義されて表示されないことは、私が行方不明です何かあるのか、私は内のノードを作成する必要がありますしていますコード?私はリストのリストのツリービューを持っているのTabControlを持っている、問題は、私はあちこち例に

stundents 
    -Student1 
     -Course 1 
     -Course 2 
      - Department 1 
    -Student 2 
     -Course 6 
      Department12 

Course 
    -Qualification 1 
     -WorkType 
+0

テンプレート –

+0

で 'のItemsSourceを'欠けている私はすでにアイテムを持っています親のテンプレートも、子ノードのテンプレートにも必要ですか? – mahlatse

+0

[msdn]からサンプルを試す(https://msdn.microsoft.com/en-us/library/dd759035(v = v1).aspx) –

答えて

2

を言っているので、もし一つのタブは、Idでリレーショナルにリンクされている別のツリービューの項目を含めることができているように、クラスを作成します。 DisplayNameおよびその他のItem秒のObservableCollectionを持っているすべてのあなたのltemsのルート、:

public class Item : INotifyPropertyChanged 
{ 
    string _displayText; 
    public string DisplayText { get { return _displayText; } set { _displayText = value; RaisePropertyChanged("DisplayText"); } } 

    ObservableCollection<Item> _items; 
    public ObservableCollection<Model> Items { get { return _items; } set { _items = value; RaisePropertyChanged("Items"); } } 

    public event PropertyChangedEventHandler PropertyChanged; 
    internal void RaisePropertyChanged(string propname) 
    { 
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propname)); 
    } 
} 

他のタイプ(学生、教師、コース、部門など)は、このクラスから派生しなければなりません。彼らは特定の特性も持っているかもしれません。あなたは(項目の異なる内側のリストで)Courseクラスの2つの種類がある場合は、それらのための2つの別々のクラスを作成することを

public class Student : Item 
{ 
} 
public class Course : Item 
{ 
} 
public class Qualification : Item 
{ 
} 

注意。

さて、あなたはpropertlyビューモデルでのObservableCollectionを移入する必要があり、すべてが次のようなツリービューでの世話をされます。

<TreeView DataContext="{Binding}" ItemsSource="{Binding Items}"> 
    <TreeView.ItemTemplate> 
     <HierarchicalDataTemplate ItemsSource="{Binding Items}"> 
      <TextBlock Text="{Binding DisplayText}"/> 
     </HierarchicalDataTemplate> 
    </TreeView.ItemTemplate> 
</TreeView> 
関連する問題