示例#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);
     }
 }
示例#2
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);
            }
        }
示例#3
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;
                }
            }
        }
示例#4
0
 public static T AncestorsFind <T>(this DependencyObject item) where T : DependencyObject
 {
     return(item.Ancestors <T>().FirstOrDefault() as T);
 }
示例#5
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));
 }