Example #1
0
        internal static void FindChildren <T>(List <T> results, Windows.UI.Xaml.DependencyObject startNode) where T : Windows.UI.Xaml.DependencyObject
        {
            int count = Windows.UI.Xaml.Media.VisualTreeHelper.GetChildrenCount(startNode);

            for (int i = 0; i < count; i++)
            {
                Windows.UI.Xaml.DependencyObject current = Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(startNode, i);
                if ((current.GetType()).Equals(typeof(T)) || (current.GetType().GetTypeInfo().IsSubclassOf(typeof(T))))
                {
                    T asType = (T)current;
                    results.Add(asType);
                }
                FindChildren <T>(results, current);
            }
        }
Example #2
0
        static public string GetDependencyPropertyName(this Windows.UI.Xaml.DependencyObject obj, Windows.UI.Xaml.DependencyProperty depprop)
        {
            foreach (var field in obj.GetType().GetFields(BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public))
            {
                if (field.FieldType == typeof(Windows.UI.Xaml.DependencyProperty) && field.GetValue(null) == depprop)
                {
                    return(field.Name);
                }
            }

            foreach (var prop in obj.GetType().GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public))
            {
                if (prop.PropertyType == typeof(Windows.UI.Xaml.DependencyProperty) && prop.GetValue(null) == depprop)
                {
                    return(prop.Name);
                }
            }

            return(null);
        }