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);
        }
Beispiel #2
0
 internal static void ForEachParent <TNodeType>(DependencyObject node, Func <TNodeType, bool> callback) where TNodeType : class
 {
     VisualTreeHelpers.ForEachParentAndNode <TNodeType>(VisualTreeHelper.GetParent(node), callback);
 }