Ejemplo n.º 1
0
        public static IEnumerable <T> Children <T>(this DependencyObject parent, Func <T, bool> predicate, WhereFlags flags)
            where T : DependencyObject
        {
            bool depthFirst    = (flags & WhereFlags.DepthFirst) == WhereFlags.DepthFirst;
            bool recursive     = (flags & WhereFlags.Recursive) == WhereFlags.Recursive;
            bool visualTree    = (flags & WhereFlags.VisualTree) == WhereFlags.VisualTree;
            bool startOnParent = (flags & WhereFlags.StartOnParent) == WhereFlags.StartOnParent;

            Func <DependencyObject, bool> finalPredicate;

            if (predicate == null)
            {
                finalPredicate = (depObj => depObj is T);
            }
            else
            {
                finalPredicate = depObj => { T elem = depObj as T; return(elem != null && predicate(elem)); }
            };

            if (visualTree)
            {
                if (depthFirst)
                {
                    return(DepthFirstVisual(parent, startOnParent, recursive, finalPredicate).Cast <T>());
                }
                else
                {
                    return(BreathFirstVisual(parent, startOnParent, recursive, finalPredicate).Cast <T>());
                }
            }
            else
            {
                if (depthFirst)
                {
                    return(DepthFirstLogical(parent, startOnParent, recursive, finalPredicate).Cast <T>());
                }
                else
                {
                    return(BreathFirstLogical(parent, startOnParent, recursive, finalPredicate).Cast <T>());
                }
            }
        }
Ejemplo n.º 2
0
 public static IEnumerable <T> Children <T>(this DependencyObject parent, string route, WhereFlags flags)
     where T : DependencyObject
 {
     return(Children <T>(parent, p => p.GetRoute() == route, flags));
 }
Ejemplo n.º 3
0
 public static IEnumerable <T> Children <T>(this DependencyObject parent, WhereFlags flags)
     where T : DependencyObject
 {
     return(Children <T>(parent, (Func <T, bool>)null, flags));
 }
Ejemplo n.º 4
0
 public static T Child <T>(this DependencyObject parent, Func <T, bool> predicate, WhereFlags flags)
     where T : DependencyObject
 {
     return(Children <T>(parent, predicate, flags).FirstEx());
 }
Ejemplo n.º 5
0
 public static T Child <T>(this DependencyObject parent, string route, WhereFlags flags)
     where T : DependencyObject
 {
     return(Children <T>(parent, p => p.GetRoute() == route, flags).FirstEx());
 }
Ejemplo n.º 6
0
 public static T Child <T>(this DependencyObject parent, WhereFlags flags)
     where T : DependencyObject
 {
     return(Children <T>(parent, (Func <T, bool>)null, flags).FirstEx());
 }