问一下有没有在WPF中实现n叉树的自定义控件 RRS feed


  • Hi    Bowen Peng,

    目前WPF中并没有提供实现n叉树的自定义的控件。 你需要自己创建或者使用WPF中典型的TreeView树形结构控件,并结合TreeView HierarchicalDataTemplate 分层数据模板来绑定多层内嵌子集合,配合自定义的逻辑,从而达到一个能实现N层的树形控件。

        <TreeView x:Name="aaaa"  ItemsSource="{Binding Items}">
                    <HierarchicalDataTemplate DataType="{x:Type local:NodeViewModel}" ItemsSource="{Binding Children}">
                        <TextBlock Text="{Binding Name}"></TextBlock>
                    <HierarchicalDataTemplate DataType="{x:Type local:Type22222}" ItemsSource="{Binding Children}">
                        <TextBlock Text="{Binding Name}"></TextBlock>
        public class NodeViewModel
            public string Id { get; set; }
            public string Name { get; set; }
            public ObservableCollection<NodeViewModel> Children { get; set; }


    Best Regards,

    Yong Lu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    2018年4月10日 5:58