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);
 }
Example #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);
 }
Example #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>
 /// 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);
         }
     }
 }