Beispiel #1
0
 internal static void InvalidateMeasureInSubtree(this UIElement element)
 {
     if (element == null || element.Visibility == Visibility.Collapsed)
     {
         return;
     }
     element.InvalidateMeasure();
     foreach (UIElement element1 in VisualTreeHelpers.GetChildren(element))
     {
         VisualTreeHelpers.InvalidateMeasureInSubtree(element1);
     }
 }
 public static void FocusDescendant(this FrameworkElement element)
 {
     VisualTreeHelpers.ForEachChildAndNodeDepth <DependencyObject>((DependencyObject)element, (Func <DependencyObject, bool>)(current =>
     {
         bool flag       = true;
         Control control = current as Control;
         if (control != null)
         {
             flag = !control.Focus();
         }
         return(flag);
     }));
 }
        public static object TryFindResource(this FrameworkElement thisObject, object resourceKey)
        {
            object requestedResource = (object)null;

            VisualTreeHelpers.ForEachParentAndNode <FrameworkElement>((DependencyObject)thisObject, (Func <FrameworkElement, bool>)(fe =>
            {
                bool flag  = true;
                object obj = fe.Resources[resourceKey];
                if (obj != null)
                {
                    requestedResource = obj;
                    flag = false;
                }
                return(flag);
            }));
            if (requestedResource == null)
            {
                requestedResource = Application.Current.Resources[resourceKey];
            }
            return(requestedResource);
        }
        public static bool IsInVisualTree(this FrameworkElement thisObject)
        {
            bool             flag           = false;
            DependencyObject visualTreeRoot = VisualTreeHelpers.GetVisualTreeRoot((DependencyObject)thisObject);

            if (visualTreeRoot == Window.GetWindow((DependencyObject)thisObject))
            {
                flag = true;
            }
            else
            {
                FrameworkElement frameworkElement = visualTreeRoot as FrameworkElement;
                if (frameworkElement != null)
                {
                    Popup popup = frameworkElement.Parent as Popup;
                    if (popup != null && popup.IsOpen)
                    {
                        flag = true;
                    }
                }
            }
            return(flag);
        }
Beispiel #5
0
 internal static void ForEachParent <TNodeType>(DependencyObject node, Func <TNodeType, bool> callback) where TNodeType : class
 {
     VisualTreeHelpers.ForEachParentAndNode <TNodeType>(VisualTreeHelper.GetParent(node), callback);
 }