예제 #1
0
		static Style FindResource(ResourceKey key)
		{
			// don't crash if controls using GlobalStyles are instanciated in unit test mode
			if (Application.Current == null)
				return null;
			else
				return (Style)Application.Current.FindResource(key);
		}
예제 #2
0
        private static object GetKey(string name, ResourceKey resourceKey)
        {
            if (environmentColors == null)
            {
                return resourceKey;
            }

            return GetValue(environmentColors, name);
        }
예제 #3
0
        /// <summary>
        ///     Searches for a resource inside a ResourceDictionary.
        /// </summary> 
        /// <param name="key">The original key.</param>
        /// <param name="typeKey">The key cast to Type.</param> 
        /// <param name="resourceKey">The key cast to ResourceKey.</param> 
        /// <param name="isTraceEnabled">Tracing on/off.</param>
        /// <param name="allowDeferredResourceReference"> 
        ///     If this flag is true the resource will not actually be inflated from Baml.
        ///     Instead we will return an instance of DeferredDictionaryReference which
        ///     can later be used to query the resource
        /// </param> 
        /// <param name="mustReturnDeferredResourceReference">
        ///     If this method is true this method will always return a 
        ///     DeferredThemeResourceReference instance which envelopes the underlying resource. 
        /// </param>
        /// <param name="canCache">Whether callers can cache the value.</param> 
        /// <returns></returns>
        private static object FindDictionaryResource(
            object      key,
            Type        typeKey, 
            ResourceKey resourceKey,
            bool        isTraceEnabled, 
            bool        allowDeferredResourceReference, 
            bool        mustReturnDeferredResourceReference,
            out bool    canCache) 
        {
            // Thread safety handled by FindResourceInternal. Be sure to have locked _resourceCache.SyncRoot.

            Debug.Assert(typeKey != null || resourceKey != null, "typeKey or resourceKey should be non-null"); 

            canCache = true; 
            object resource = null; 
            Assembly assembly = (typeKey != null) ? typeKey.Assembly : resourceKey.Assembly;
 
            if ((assembly == null) || IgnoreAssembly(assembly))
            {
                // Without an assembly, we can't figure out which dictionary to look at.
                // Also, ignore some common assemblies we know to not contain resources. 
                return null;
            } 
 
            ResourceDictionaries dictionaries = EnsureDictionarySlot(assembly);
            ResourceDictionary dictionary = dictionaries.LoadThemedDictionary(isTraceEnabled); 
            if (dictionary != null)
            {
                resource = LookupResourceInDictionary(dictionary, key, allowDeferredResourceReference, mustReturnDeferredResourceReference, out canCache);
            } 

            if (resource == null) 
            { 
                dictionary = dictionaries.LoadGenericDictionary(isTraceEnabled);
                if (dictionary != null) 
                {
                    resource = LookupResourceInDictionary(dictionary, key, allowDeferredResourceReference, mustReturnDeferredResourceReference, out canCache);
                }
            } 

            if (resource != null) 
            { 
                // Resources coming out of the dictionary may need to be frozen
                Freeze(resource); 
            }

            return resource;
        } 
		public ResourceKeyHighlightingBrush(ResourceKey key, string name)
		{
		}
예제 #5
0
 private static ICommand CreateThemeCommand(ResourceKey key)
 {
     var theme = (ResourceDictionary)Application.Current.FindResource(key);
     return new ApplyThemeCommand(theme);
 }
예제 #6
0
        private static void CoerceColor(DependencyObject d, object baseValue, ResourceKey brushKey,
            IList<DependencyObject> colorBoundObjects)
        {
            if (d is ItemsControl && baseValue is Color)
            {
                var itemCtrl = (ItemsControl)d;
                var res = itemCtrl.Resources;

                if (!res.IsReadOnly)
                {
                    var color = (Color)baseValue;
                    var brush = new SolidColorBrush(color);
                    res[brushKey] = brush;
                }

                colorBoundObjects.Add(d);
            }
        }