mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
25 lines
743 B
C#
25 lines
743 B
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
|
|
namespace Artemis.UI.Extensions
|
|
{
|
|
public static class TreeViewItemExtensions
|
|
{
|
|
public static int GetDepth(this TreeViewItem item)
|
|
{
|
|
TreeViewItem parent;
|
|
while ((parent = GetParent(item)) != null)
|
|
return GetDepth(parent) + 1;
|
|
return 0;
|
|
}
|
|
|
|
private static TreeViewItem GetParent(TreeViewItem item)
|
|
{
|
|
DependencyObject parent = VisualTreeHelper.GetParent(item);
|
|
while (!(parent is TreeViewItem || parent is TreeView))
|
|
parent = VisualTreeHelper.GetParent(parent);
|
|
return parent as TreeViewItem;
|
|
}
|
|
}
|
|
} |