mirror of
https://github.com/ckaczor/Common.Wpf.git
synced 2026-01-14 01:25:37 -05:00
Initial commit
This commit is contained in:
20
Extensions/DependencyObjectExtensions.cs
Normal file
20
Extensions/DependencyObjectExtensions.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user