Skip to content

Commit bc99be6

Browse files
committed
rename IsDescendant() to IsAncestorOf(), rename HasAncestor() to IsDescendantOf(), new implementaiton of IsDescendantOf()
1 parent 0172aae commit bc99be6

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

MaterialDesignThemes.Wpf/ComboBoxPopup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private CustomPopupPlacement[] ComboBoxCustomPopupPlacementCallback(Size popupSi
106106
{
107107
var locationFromScreen = this.PlacementTarget.PointToScreen(new Point(0, 0));
108108

109-
var mainVisual = PlacementTarget.GetVisualAncestory().OfType<System.Windows.Media.Visual>().LastOrDefault();
109+
var mainVisual = PlacementTarget.GetVisualAncestry().OfType<System.Windows.Media.Visual>().LastOrDefault();
110110
if (mainVisual == null) return new CustomPopupPlacement[0];
111111

112112
var screenWidth = (int) DpiHelper.TransformToDeviceX(mainVisual, SystemParameters.PrimaryScreenWidth);

MaterialDesignThemes.Wpf/Extensions.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ public static IEnumerable<DependencyObject> VisualDepthFirstTraversal(this Depen
2424
}
2525
}
2626

27-
public static bool IsDescendant(this DependencyObject parent, DependencyObject node)
27+
public static bool IsAncestorOf(this DependencyObject parent, DependencyObject node)
2828
{
2929
return node != null && parent.VisualDepthFirstTraversal().Contains(node);
3030
}
3131

3232
/// <summary>
33-
/// Returns full visual ancestory, starting at the leaf.
33+
/// Returns full visual ancestry, starting at the leaf.
3434
/// </summary>
3535
/// <param name="leaf"></param>
3636
/// <returns></returns>
37-
public static IEnumerable<DependencyObject> GetVisualAncestory(this DependencyObject leaf)
37+
public static IEnumerable<DependencyObject> GetVisualAncestry(this DependencyObject leaf)
3838
{
3939
while (leaf != null)
4040
{
@@ -43,7 +43,7 @@ public static IEnumerable<DependencyObject> GetVisualAncestory(this DependencyOb
4343
}
4444
}
4545

46-
public static IEnumerable<DependencyObject> GetLogicalAncestory(this DependencyObject leaf)
46+
public static IEnumerable<DependencyObject> GetLogicalAncestry(this DependencyObject leaf)
4747
{
4848
while (leaf != null)
4949
{
@@ -52,17 +52,18 @@ public static IEnumerable<DependencyObject> GetLogicalAncestory(this DependencyO
5252
}
5353
}
5454

55-
public static bool HasAncestor(this DependencyObject leaf, DependencyObject ancestor)
55+
public static bool IsDescendantOf(this DependencyObject leaf, DependencyObject ancestor)
5656
{
57-
var visualAncestry = leaf.GetVisualAncestory().ToArray();
58-
if (visualAncestry.Contains(ancestor))
57+
DependencyObject parent = null;
58+
foreach (var node in leaf.GetVisualAncestry())
5959
{
60-
return true;
60+
if (Equals(node, ancestor))
61+
return true;
62+
63+
parent = node;
6164
}
6265

63-
var lastVisualAncestor = visualAncestry.LastOrDefault();
64-
var logicalAncestry = GetLogicalAncestory(lastVisualAncestor);
65-
return logicalAncestry.Contains(ancestor);
66+
return parent != null && parent.GetLogicalAncestry().Contains(ancestor);
6667
}
6768
}
6869
}

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,14 @@ private static void OnLostMouseCapture(object sender, MouseEventArgs e)
578578
{
579579
if (e.OriginalSource == popupBox)
580580
{
581-
if (Mouse.Captured == null || popupBox._popup == null || !(Mouse.Captured as DependencyObject).HasAncestor(popupBox._popup))
581+
if (Mouse.Captured == null || popupBox._popup == null || !(Mouse.Captured as DependencyObject).IsDescendantOf(popupBox._popup))
582582
{
583583
popupBox.Close();
584584
}
585585
}
586586
else
587587
{
588-
if ((Mouse.Captured as DependencyObject).GetVisualAncestory().Contains(popupBox._popup))
588+
if ((Mouse.Captured as DependencyObject).GetVisualAncestry().Contains(popupBox._popup))
589589
{
590590
// Take capture if one of our children gave up capture (by closing their drop down)
591591
if (popupBox.IsPopupOpen && Mouse.Captured == null && GetCapture() == IntPtr.Zero)

0 commit comments

Comments
 (0)