programming-examples/c-sharp/Others/Is Logical Ancestor Of.cs
2019-11-15 12:59:38 +01:00

28 lines
758 B
C#

Is Logical Ancestor Of
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
public static class PopupHelper
{
public static bool IsLogicalAncestorOf(this UIElement ancestor, UIElement child)
{
if (child != null)
{
FrameworkElement obj = child as FrameworkElement;
while (obj != null)
{
FrameworkElement parent = VisualTreeHelper.GetParent(obj) as FrameworkElement;
obj = parent == null ? obj.Parent as FrameworkElement : parent as FrameworkElement;
if (obj == ancestor) return true;
}
}
return false;
}
}