Is it wrong to access TreeViewItems in WPF’s TreeView?

前端 未结 4 807
半阙折子戏
半阙折子戏 2021-01-26 15:00

I’ve been having issues with the TreeView in WPF. This control makes it very hard to access the TreeViewItems it’s showing.

On several occasion

4条回答
  •  野性不改
    2021-01-26 15:41

    Admittedly this is not straightforward but you can probably still do this while keeping a separation which does not require you to access the TreeViewItems knowingly. The essence in WPF is binding as already noted by Kent Boogaart in your other question, here however you need to somehow deal with events. Your view-model needs to fire a BringIntoView event of its own while the view needs to react.

    The easiest method might be to add a EventSetter on Loaded to make the TreeViewItems subscribe to said event on their DataContext which should be your view-model (if it isn't you can wait for DataContextChanged).

提交回复
热议问题