mirror of
https://github.com/4sval/FModel.git
synced 2026-09-20 07:24:45 -05:00
21 lines
533 B
C#
21 lines
533 B
C#
using System.Windows;
|
|
using System.Windows.Media;
|
|
|
|
namespace FModel.Extensions;
|
|
|
|
public static class VisualTreeExtensions
|
|
{
|
|
public static T FindAncestor<T>(this DependencyObject current) where T : DependencyObject
|
|
{
|
|
while (current != null)
|
|
{
|
|
if (current is T t)
|
|
return t;
|
|
current = current is FrameworkContentElement contentElement
|
|
? contentElement.Parent
|
|
: VisualTreeHelper.GetParent(current);
|
|
}
|
|
return null;
|
|
}
|
|
}
|