开发者

How to get the header of the parent node of a selected TreeViewItem?

I have this TreeView:

Main Node Header=开发者_运维问答"Main"
   Sub Node Header="Sub1"
      Final Node Header="Item1"
      Final Node Header="Item2"
   Sub Node Header="Sub 2"
      Final Node Header="Item1"
      Final Node Header="Item2"

I have two textboxes that are bound to this TreeView. One has its Text property bound to the TreeView's SelectedItem property and works OK.

The other TextBox I want to bind to the Header text of the Sub Node directly above the selected Item.

How do I reference it?


The correct way would be to manifest the child/parent relationship in your view models and have your bindings work against the view model objects rather than the view objects.

An alternative would be to write a value converter that looks up the parent TreeViewItem for a given TreeViewItem and bind to SelectedItem using that converter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜