static TItem GetItemCore <TItem>(Visual visual, IsMatch <TItem> isMatch, Next <TItem> next)
     where TItem : Visual
 {
     foreach (var element in VisualTreeUtility.GetChildren(visual))
     {
         Visual o    = element;
         var    item = o as TItem;
         if (item != null)
         {
             if (isMatch(item))
             {
                 return(item);
             }
         }
         else
         {
             var popup = o as Popup;
             if (popup != null)
             {
                 o = popup.Child as Visual;
             }
             var nextItem = next(o);
             if (nextItem != null)
             {
                 return(nextItem);
             }
         }
     }
     return(null);
 }
Пример #2
0
 /// <summary>
 /// GetCoreElement.
 /// </summary>
 /// <param name="visual">Root.</param>
 /// <param name="type">Type.</param>
 /// <returns>Match visual.</returns>
 public static Visual GetCoreElement(Visual visual, Type type)
 {
     foreach (var v in VisualTreeUtility.GetChildren(visual))
     {
         if (type.IsAssignableFrom(v.GetType()))
         {
             return(v);
         }
         Visual o = GetCoreElement(v, type);
         if (o != null)
         {
             return(o);
         }
     }
     return(null);
 }
Пример #3
0
 /// <summary>
 /// FindVisualItem
 /// </summary>
 /// <typeparam name="T">Param type.</typeparam>
 /// <param name="visual">Visual.</param>
 /// <param name="param">Param.</param>
 /// <param name="isMatchParam">IsMatchParam.</param>
 /// <returns>Match object.</returns>
 public static object FindVisualItem <T>(Visual visual, T param, IsMatchParam <T> isMatchParam)
 {
     foreach (var v in VisualTreeUtility.GetChildren(visual))
     {
         if (isMatchParam(v, param))
         {
             return(v);
         }
         object o = FindVisualItem <T>(v, param, isMatchParam);
         if (o != null)
         {
             return(o);
         }
     }
     return(null);
 }
        /// <summary>
        /// Get item text.
        /// </summary>
        /// <param name="item">Item.</param>
        /// <returns>text.</returns>
        public static string GetItemText(Visual item)
        {
            var block = VisualTreeUtility.GetCoreElement(item, typeof(TextBlock)) as TextBlock;

            if (block != null)
            {
                if (!string.IsNullOrEmpty(block.Text))
                {
                    return(block.Text);
                }
            }
            var access = VisualTreeUtility.GetCoreElement(item, typeof(AccessText)) as AccessText;

            if (access != null)
            {
                if (!string.IsNullOrEmpty(access.Text))
                {
                    return(access.Text);
                }
            }
            return(string.Empty);
        }
 /// <summary>
 /// GetChildren
 /// </summary>
 /// <typeparam name="T">Child item type.</typeparam>
 /// <param name="v">visual.</param>
 /// <param name="itmes">Children.</param>
 public static void GetChildren <T>(Visual v, List <T> itmes)
     where T : class
 {
     foreach (var element in VisualTreeUtility.GetChildren(v))
     {
         var menuItem = element as T;
         if (menuItem != null)
         {
             itmes.Add(menuItem);
         }
         else
         {
             var next  = element;
             var popup = next as Popup;
             if (popup != null)
             {
                 next = popup.Child as Visual;
             }
             GetChildren(next, itmes);
         }
     }
 }