mirror of
https://github.com/ckaczor/Common.Wpf.git
synced 2026-01-14 01:25:37 -05:00
21 lines
547 B
C#
21 lines
547 B
C#
using System.Windows;
|
|
using System.Windows.Media;
|
|
|
|
namespace Common.Wpf.Extensions
|
|
{
|
|
public static class DependencyObjectExtensions
|
|
{
|
|
public static T GetAncestor<T>(this DependencyObject referenceObject) where T : class
|
|
{
|
|
DependencyObject parent = VisualTreeHelper.GetParent(referenceObject);
|
|
|
|
while (parent != null && !parent.GetType().Equals(typeof(T)))
|
|
{
|
|
parent = VisualTreeHelper.GetParent(parent);
|
|
}
|
|
|
|
return parent as T;
|
|
}
|
|
}
|
|
}
|