How to filter a wpf treeview hierarchy using an ICollectionView?

前端 未结 6 1911
盖世英雄少女心
盖世英雄少女心 2020-12-29 22:26

I have a hypothetical tree view that contains this data:

RootNode
   Leaf
   vein
SecondRoot
   seeds
   flowers

I am trying to filter the

6条回答
  •  庸人自扰
    2020-12-29 22:42

    Unfortunately there is no way to make same Filter apply to all nodes automatically. Filter is a property (not a DP) of ItemsCollection which is not DependencyObject and so DP Value inheritance isn't there.

    Each node in the tree has its own ItemsCollection which has its own Filter. The only way to make it work is to manually set them all to call the same delegate.

    Simplest way would be to expose Filter property of type Predicate at your ToolBoxViewModel and in its setter fire an event. Then ToolboxItemViewModel will be responsible for consuming this event and updating its Filter.

    Aint pretty and I'm not sure what the performance would be like for large amounts of items in the tree.

    提交回复
    热议问题