Dreamine.UI.Wpf.Equipment 1.0.1
Dreamine.UI.Wpf.Equipment 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
TreeHelper.cs
이 파일의 문서화 페이지로 가기
1using System.Windows;
2using System.Windows.Media;
3
5
14public static class TreeHelper
15{
48 public static IEnumerable<T> FindVisualChildren<T>(this DependencyObject dep) where T : DependencyObject
49 {
50 if (dep == null)
51 yield break;
52
53 for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dep); i++)
54 {
55 var child = VisualTreeHelper.GetChild(dep, i);
56 if (child is T t)
57 yield return t;
58
59 foreach (var childOfChild in FindVisualChildren<T>(child))
60 yield return childOfChild;
61 }
62 }
63
104 public static T? FindFirstVisualChild<T>(this DependencyObject dep, string name) where T : FrameworkElement
105 {
106 if (dep == null)
107 return null;
108
109 for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dep); i++)
110 {
111 var child = VisualTreeHelper.GetChild(dep, i);
112
113 if (child is T t && t.Name == name)
114 return t;
115
116 var result = FindFirstVisualChild<T>(child, name);
117 if (result != null)
118 return result;
119 }
120
121 return null;
122 }
123
156 public static T? FindFirstVisualChild<T>(this DependencyObject dep) where T : FrameworkElement
157 {
158 if (dep == null)
159 return null;
160
161 for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dep); i++)
162 {
163 var child = VisualTreeHelper.GetChild(dep, i);
164
165 if (child is T t)
166 return t;
167
168 var result = FindFirstVisualChild<T>(child);
169 if (result != null)
170 return result;
171 }
172
173 return null;
174 }
175
216 public static T FindParent<T>(DependencyObject child) where T : DependencyObject
217 {
218 DependencyObject parentObject = VisualTreeHelper.GetParent(child);
219
220 while (parentObject != null)
221 {
222 if (parentObject is T parent)
223 return parent;
224
225 parentObject = VisualTreeHelper.GetParent(parentObject);
226 }
227
228 return null!;
229 }
230}
static IEnumerable< T > FindVisualChildren< T >(this DependencyObject dep)
Definition TreeHelper.cs:48
static ? T FindFirstVisualChild< T >(this DependencyObject dep, string name)