我想將我的Node類的對象綁定到樹視圖。將包含不同列表<T>的自定義對象綁定到TreeView
節點類
public class Node
{
public string Text { get; set; }
public List<Node> Child { get; set; }
public List<NodeAttribute> Attributes { get; set; }
public bool IsLeafNode { get; set; }
public bool HasAttributes { get; set; }
}
NodeAttribute
public class NodeAttribute
{
public string Attribute { get; set; }
public string Value { get; set; }
}
我能夠使用HierarchicalDataTemplate而不是屬性來dislplay兒童。
<TreeView Name="tv" ItemsSource="{Binding Child}">
<TreeView.Resources>
<HierarchicalDataTemplate ItemsSource="{Binding Child}" DataType="{x:Type tvcc:Node}">
<StackPanel>
<TextBlock Text="{Binding Text}"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
我想樣式Child和屬性不同。