wabbajack/Wabbajack/Themes/TreeViewItemExtensions.cs

28 lines
764 B
C#
Raw Normal View History

2019-09-14 04:35:42 +00:00
using System.Windows.Controls;
2019-07-31 03:59:19 +00:00
using System.Windows.Media;
namespace DarkBlendTheme
{
public static class TreeViewItemExtensions
{
public static int GetDepth(this TreeViewItem item)
{
TreeViewItem parent;
2019-09-14 04:35:42 +00:00
while ((parent = GetParent(item)) != null) return GetDepth(parent) + 1;
2019-07-31 03:59:19 +00:00
return 0;
}
private static TreeViewItem GetParent(TreeViewItem item)
{
var parent = VisualTreeHelper.GetParent(item);
2019-09-14 04:35:42 +00:00
2019-07-31 03:59:19 +00:00
while (!(parent is TreeViewItem || parent is TreeView))
{
2019-09-14 04:35:42 +00:00
if (parent == null) return null;
2019-07-31 03:59:19 +00:00
parent = VisualTreeHelper.GetParent(parent);
}
2019-09-14 04:35:42 +00:00
2019-07-31 03:59:19 +00:00
return parent as TreeViewItem;
}
}
2019-09-14 04:35:42 +00:00
}