开发者

how to get header controls in data bound TreeView

开发者 https://www.devze.com 2022-12-30 02:27 出处:网络
I have TreeView with hierarchical data binding. I want to get TreeViewItem.Header controls not my MVVM. I can get TreeViewItem using TreeView.ItemContainerGenerator.ContainerFromIndex() method... but

I have TreeView with hierarchical data binding. I want to get TreeViewItem.Header controls not my MVVM. I can get TreeViewItem using TreeView.ItemContainerGenerator.ContainerFromIndex() method... but how to get TreeViewItem.Header ?

开发者_如何学C

Regards, Marcin


It is very simple:

var item = TreeView.ItemContainerGenerator.ContainerFromIndex(...);
var header = ((TreeViewItem)item).Header;

However it may not be a good idea: Generally any code that requires access to the header control itself (as opposed to the model) is poorly written and should be rewritten to use data binding instead.

0

精彩评论

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