WPF TreeView databinding to hide/show expand/collapse icon

后端 未结 2 2023
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 01:29

I implemented a WPF load-on-demand treeview like described in this (very good) article. In the mentioned solution a dummy element is used to preserve the expand +

2条回答
  •  粉色の甜心
    2021-01-06 01:54

    After quickly looking into Josh's code, I found this constructor:

    protected TreeViewItemViewModel(TreeViewItemViewModel parent, bool lazyLoadChildren)
    {
        _parent = parent;
    
        _children = new ObservableCollection();
    
        if (lazyLoadChildren)
            _children.Add(DummyChild);
    }
    

    So, if you pass false for the lazyLoadChildren parameter from your inheriting ViewModel classes, the + icon should not appear because the DummyChild is not added. Since you seem to know whether your items have children or not, you should be able to pass the appropriate value for the lazyLoadChildren property. Or am I missing something?

提交回复
热议问题