Dreamine.MVVM.Locators.Wpf 1.0.7
Dreamine.MVVM.Locators.Wpf 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
RegionBinderHelper.cs
이 파일의 문서화 페이지로 가기
1using System;
2using System.Windows;
3using System.Windows.Controls;
4using System.Windows.Media;
5
7{
16 public static class RegionBinderHelper
17 {
66 public static ContentControl? FindRegionControl(DependencyObject root, string regionName)
67 {
68 ArgumentNullException.ThrowIfNull(root);
69
70 if (string.IsNullOrWhiteSpace(regionName))
71 {
72 throw new ArgumentException("Region name must not be empty.", nameof(regionName));
73 }
74
75 int childCount = VisualTreeHelper.GetChildrenCount(root);
76 for (int i = 0; i < childCount; i++)
77 {
78 DependencyObject child = VisualTreeHelper.GetChild(root, i);
79
80 if (child is ContentControl contentControl &&
81 string.Equals(RegionBinder.GetRegionName(contentControl), regionName, StringComparison.Ordinal))
82 {
83 return contentControl;
84 }
85
86 ContentControl? result = FindRegionControl(child, regionName);
87 if (result is not null)
88 {
89 return result;
90 }
91 }
92
93 return null;
94 }
95 }
96}
static ? string GetRegionName(DependencyObject obj)
static ? ContentControl FindRegionControl(DependencyObject root, string regionName)