WPF: Is there a built-in TreeGrid / TreeListView?

前端 未结 7 1252
长情又很酷
长情又很酷 2020-12-29 21:05

I need something just like this:

(I need both the TreeView and the ListView aspects. That is, Hirearchy and Columns.)

But, I need it in WPF. is thi

7条回答
  •  爱一瞬间的悲伤
    2020-12-29 21:27

    This one works like a charm for me. https://www.codeproject.com/Articles/30721/WPF-TreeListView-Control

    • you implement ITreeModel with GetChildren und HasChildren. Best to check the example code with the registry example to understand how its done. For some reason the developer forgot to add a simple example...
    • you have to add dependency properties yourself to the control to get it to work with MVVM. So it may need some tweaking. Add this to TreeList.cs to be able to bind the TreeModel:

     

    public ITreeModel TreeModel
    {
        get => (ITreeModel)GetValue(TreeModelProperty);
        set => SetValue(TreeModelProperty, value);
    }
    
    public static readonly DependencyProperty TreeModelProperty =
        DependencyProperty.Register(
            "TreeModel",
            typeof(ITreeModel), 
            typeof(TreeList), 
            new PropertyMetadata(null, OnModelChanged));
    
    private static void OnModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var treeList = (TreeList) d;
        treeList.Root.Children.Clear();
        treeList.Rows.Clear();
        treeList.CreateChildrenNodes(treeList.Root);
    }
    

提交回复
热议问题