-
[WPF] Find ParentC#/WPF 2023. 5. 31. 16:56
private static T FindParent<T>(DependencyObject child, string parentName) where T : DependencyObject { if (child == null) return null; T foundParent = null; var currentParent = VisualTreeHelper.GetParent(child); do { var frameworkElement = currentParent as FrameworkElement; if(frameworkElement.Name == parentName && frameworkElement is T) { foundParent = (T) currentParent; break; } currentParent = VisualTreeHelper.GetParent(currentParent); } while (currentParent != null); return foundParent; }
https://stackoverflow.com/questions/15198104/find-parent-of-control-by-name
728x90'C# > WPF' 카테고리의 다른 글
[WPF] Platform (0) 2023.06.07 [WPF] PostBuildEvent (0) 2023.06.01 [WPF] EventHandler (0) 2023.05.31 [WPF] Access view control from viewmodel (0) 2023.05.31 [WPF] ReadOnly Property (0) 2023.05.24 댓글