mirror of
https://github.com/4sval/FModel.git
synced 2026-09-23 16:55:49 -05:00
Some checks failed
FModel QA Builder / build (push) Has been cancelled
Global search jump to asset should now be instantaneous PUBG/ABI/Conan Exiles Enhanced update, New Gundam Breaker/Destroy All Humans 2 Reprobed support, Delta Force/Roco/Splitgate2 fixes Co-Authored-By: LongerWarrior <37636768+LongerWarrior@users.noreply.github.com> Co-Authored-By: Adain Rivers <93623214+adainrivers@users.noreply.github.com> Co-Authored-By: Abishek <73873078+Abishek82828@users.noreply.github.com> Co-Authored-By: Valentin <26126862+4sval@users.noreply.github.com> Co-Authored-By: Mao <60669781+hexaov91@users.noreply.github.com> Co-Authored-By: Luke <17146677+LukeFZ@users.noreply.github.com>
37 lines
987 B
C#
37 lines
987 B
C#
using System.Windows;
|
|
using System.Windows.Media;
|
|
|
|
namespace FModel.Extensions;
|
|
|
|
public static class VisualTreeExtensions
|
|
{
|
|
public static T FindAncestor<T>(this DependencyObject current) where T : DependencyObject
|
|
{
|
|
while (current != null)
|
|
{
|
|
if (current is T t)
|
|
return t;
|
|
current = current is FrameworkContentElement contentElement
|
|
? contentElement.Parent
|
|
: VisualTreeHelper.GetParent(current);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static T? FindVisualChild<T>(this DependencyObject parent) where T : DependencyObject
|
|
{
|
|
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
|
{
|
|
var child = VisualTreeHelper.GetChild(parent, i);
|
|
if (child is T result)
|
|
return result;
|
|
|
|
if (FindVisualChild<T>(child) is { } descendant)
|
|
return descendant;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
}
|