Skip to content

Commit a43c13a

Browse files
authored
Check for Visual or Visual3D in visual ancestry (#2134) (#2276)
1 parent d51a06f commit a43c13a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

MaterialDesignThemes.Wpf/Extensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Windows;
55
using System.Windows.Media;
6+
using System.Windows.Media.Media3D;
67

78
namespace MaterialDesignThemes.Wpf
89
{
@@ -50,6 +51,8 @@ public static bool IsAncestorOf(this DependencyObject parent, DependencyObject?
5051

5152
/// <summary>
5253
/// Returns full visual ancestry, starting at the leaf.
54+
/// <para>If element is not of <see cref="Visual"/> or <see cref="Visual3D"/> the
55+
/// logical ancestry is used.</para>
5356
/// </summary>
5457
/// <param name="leaf"></param>
5558
/// <returns></returns>
@@ -58,7 +61,9 @@ public static IEnumerable<DependencyObject> GetVisualAncestry(this DependencyObj
5861
while (leaf is not null)
5962
{
6063
yield return leaf;
61-
leaf = VisualTreeHelper.GetParent(leaf);
64+
leaf = leaf is Visual || leaf is Visual3D
65+
? VisualTreeHelper.GetParent(leaf)
66+
: LogicalTreeHelper.GetParent(leaf);
6267
}
6368
}
6469

0 commit comments

Comments
 (0)