Exemple #1
0
 /// <summary>
 /// Returns a collection of the sibling elements before this node, in document order.
 /// </summary>
 public static IEnumerable<DependencyObject> ElementsBeforeSelf(this DependencyObject item)
 {
   if (item.Ancestors().FirstOrDefault() == null)
     yield break;
   foreach (var child in item.Ancestors().First().Elements())
   {
     if (child.Equals(item))
       break;
     yield return child;
   }
 }
Exemple #2
0
    /// <summary>
    /// Returns a collection of the after elements after this node, in document order.
    /// </summary>
    public static IEnumerable<DependencyObject> ElementsAfterSelf(this DependencyObject item)
    {
      if (item.Ancestors().FirstOrDefault() == null)
        yield break;
      bool afterSelf = false;
      foreach (var child in item.Ancestors().First().Elements())
      {
        if (afterSelf)
          yield return child;

        if (child.Equals(item))
          afterSelf = true;
      }
    }
Exemple #3
0
        public static IEnumerable <DependencyObject> CommonAncestors(this DependencyObject obj1, DependencyObject obj2)
        {
            var ancestors1 = obj1.Ancestors().Reverse();
            var ancestors2 = obj2.Ancestors().Reverse();

            return(ancestors1.FirstEquals(ancestors2));
        }
        public static T TryFindAncestor <T>([NotNull] this DependencyObject self, [NotNull] Func <T, bool> match)
        {
            Contract.Requires(self != null);
            Contract.Requires(match != null);

            return(self.Ancestors().OfType <T>().FirstOrDefault(match));
        }
 public static IEnumerable <DependencyObject> ElementsBeforeSelf(this DependencyObject item)
 {
     if (item.Ancestors().FirstOrDefault <DependencyObject>() != null)
     {
         foreach (DependencyObject element in item.Ancestors().First <DependencyObject>().Elements())
         {
             if (!element.Equals((object)item))
             {
                 yield return(element);
             }
             else
             {
                 break;
             }
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// Returns a collection containing this element and all ancestor elements.
        /// </summary>
        public static IEnumerable <DependencyObject> AncestorsAndSelf(this DependencyObject item)
        {
            yield return(item);

            foreach (var ancestor in item.Ancestors())
            {
                yield return(ancestor);
            }
        }
Exemple #7
0
 /// <summary>
 /// Find the parent frame of the object
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public static ModernFrame FindParentFrame(this DependencyObject context)
 {
     if (context == null)
     {
         return(null);
     }
     return(context.Ancestors()
            .OfType <ModernFrame>()
            .FirstOrDefault());
 }
 public static IEnumerable <DependencyObject> ElementsAfterSelf(this DependencyObject item)
 {
     if (item.Ancestors().FirstOrDefault <DependencyObject>() != null)
     {
         bool afterSelf = false;
         foreach (DependencyObject element in item.Ancestors().First <DependencyObject>().Elements())
         {
             DependencyObject child = element;
             if (afterSelf)
             {
                 yield return(child);
             }
             if (child.Equals((object)item))
             {
                 afterSelf = true;
             }
             child = (DependencyObject)null;
         }
     }
 }
Exemple #9
0
 /// <summary>
 /// Returns a collection of ancestor elements which match the given type.
 /// </summary>
 public static IEnumerable <DependencyObject> Ancestors <T>(this DependencyObject item)
 {
     return(item.Ancestors().Where(i => i is T).Cast <DependencyObject>());
 }
 /// <summary>
 /// Returns a collection of ancestor elements which match the given type.
 /// </summary>
 public static IEnumerable <T> Ancestors <T>(this DependencyObject item)
 {
     return(item.Ancestors().OfType <T>());
 }
 public static T TryFindAncestor <T>([NotNull] this DependencyObject self, [NotNull] Func <T, bool> match)
 {
     return(self.Ancestors().OfType <T>().FirstOrDefault(match));
 }
 public static T TryFindAncestor <T>([NotNull] this DependencyObject self)
 {
     return(self.Ancestors().OfType <T>().FirstOrDefault());
 }
        public static T TryFindAncestor <T>([NotNull] this DependencyObject self)
        {
            Contract.Requires(self != null);

            return(self.Ancestors().OfType <T>().FirstOrDefault());
        }
Exemple #14
0
 private MainWindow GetMainWindow(DependencyObject button) => button.Ancestors().OfType <MainWindow>().FirstOrDefault();
 /// <summary>
 /// Returns the next ancestor of type T
 /// </summary>
 /// <param name="item"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T Ancestor <T>(this DependencyObject item) where T : DependencyObject
 {
     return(item.Ancestors().FirstOrDefault(i => i is T) as T);
 }