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

前端 未结 4 743
半阙折子戏
半阙折子戏 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:59

    I’ve come to the conclusion that it can’t be altogether wrong. The first piece of evidence comes from Bea Stollnitz’s post about ListView: if one of the WPF developers explains how this might be done, it can’t be that wrong.

    The other piece of evidence comes from this highly-voted question/answer: MVVM madness. MVVM undoubtedly has its benefits, but sometimes the cost of following MVVM is so high that it’s just silly following through with it, especially in a small one-man application. Do you really want to expose IsSelected and IsExpanded the way you’re supposed to?

    As a result, I felt justified to try and figure out how to expose the TreeViewItem corresponding to an item with less effort from the developer, under the assumption that they will never need the more advanced features that resulted in TreeViewItems being this hard to access (like displaying the same ViewModels in multiple different controls... how often have you needed that!...)

    I posted the result of this effort as an answer on another question.

提交回复
热议问题