Highlight whole TreeViewItem line in WPF

前端 未结 9 709
暗喜
暗喜 2020-11-30 17:48

If I set TreeViewItem Background it highlights the header only. How can I highlight the whole line?

I have found a post almost solving a problem http://social.msdn.

9条回答
  •  一生所求
    2020-11-30 18:46

    Used something like theseven7 to facilitate use of bendewey's code with templated TreeViewItems...

        public static int GetDepth(this TreeViewItem item)
        {
            FrameworkElement elem = item;
            var parent = VisualTreeHelper.GetParent(item);
            var count = 0;
            while (parent != null && !(parent is TreeView))
            {
                var tvi = parent as TreeViewItem;
                if (parent is TreeViewItem)
                    count++;
                parent = VisualTreeHelper.GetParent(parent);
            }
            return count;
        }
    

提交回复
热议问题