diff options
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs')
-rw-r--r-- | Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs b/Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs index 64b2daab..eb040e02 100644 --- a/Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs +++ b/Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using Windows.UI.Xaml; @@ -71,6 +72,23 @@ namespace Xamarin.Forms.Platform.WinRT element.SetBinding(GetForegroundProperty(element), binding); } + internal static IEnumerable<T> GetDescendantsByName<T>(this DependencyObject parent, string elementName) where T : DependencyObject + { + int myChildrenCount = VisualTreeHelper.GetChildrenCount(parent); + for (int i = 0; i < myChildrenCount; i++) + { + var child = VisualTreeHelper.GetChild(parent, i); + var controlName = child.GetValue(FrameworkElement.NameProperty) as string; + if (controlName == elementName && child is T) + yield return child as T; + else + { + foreach (var subChild in child.GetDescendantsByName<T>(elementName)) + yield return subChild; + } + } + } + internal static T GetFirstDescendant<T>(this DependencyObject element) where T : FrameworkElement { int count = VisualTreeHelper.GetChildrenCount(element); |