Find Child:
private DependencyObject FindChildControl<T>(DependencyObject control) { int childNumber = VisualTreeHelper.GetChildrenCount(control); for (int i = 0; i < childNumber; i++) { DependencyObject child = VisualTreeHelper.GetChild(control, i); if (child != null && child is T) return child; else FindChildControl<T>(child); } return null; }
Find Parent:
private DependencyObject FindParentControl<T>(DependencyObject control)
{
DependencyObject parent = VisualTreeHelper.GetParent(control);
while (parent != null && !(parent is T))
{
parent = VisualTreeHelper.GetParent(parent);
}
return parent;
}
Enjoy !
אין תגובות:
הוסף רשומת תגובה