public static T GetParent<T>(DependencyObject child) where T : DependencyObject { DependencyObject dependencyObject = VisualTreeHelper.GetParent(child); if (dependencyObject != null) { T parent = dependencyObject as T; if (parent != null) { return parent; } else { return GetParent <T>(dependencyObject); } } else { return null; } }
时间: 2024-10-10 17:29:17