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 ?
开发者_如何学CRegards, 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.
精彩评论