mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-11-22 17:29:18 +01:00
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Media;
|
|
|
|
namespace DS4WinWPF.DS4Forms
|
|
{
|
|
public static class UtilMethods
|
|
{
|
|
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj)
|
|
where T : DependencyObject
|
|
{
|
|
if (depObj != null)
|
|
{
|
|
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
|
|
{
|
|
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
|
|
if (child != null && child is T)
|
|
{
|
|
yield return (T)child;
|
|
}
|
|
|
|
foreach (T childOfChild in FindVisualChildren<T>(child))
|
|
{
|
|
yield return childOfChild;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static childItem FindVisualChild<childItem>(DependencyObject obj)
|
|
where childItem : DependencyObject
|
|
{
|
|
foreach (childItem child in FindVisualChildren<childItem>(obj))
|
|
{
|
|
return child;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|