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

全部回复

  • Hi    Bowen Peng,

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

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

    通过指定DataType对象类型还能组合不同的类型集合。

    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 MSDNFSF@microsoft.com.

    2018年4月10日 5:58
    版主