コード例 #1
0
        private object FindResourceInEnviroment(IServiceProvider serviceProvider,
                                                bool allowDeferredReference,
                                                bool mustReturnDeferredResourceReference)
        {
            ResourceDictionary dictionaryWithKey = FindTheResourceDictionary(serviceProvider, /* isDeferredContentSearch */ false);

            if (dictionaryWithKey != null)
            {
                object value = dictionaryWithKey.Lookup(ResourceKey, allowDeferredReference, mustReturnDeferredResourceReference, canCacheAsThemeResource: false);
                return(value);
            }

            // Look at app or themes
            object val = FindResourceInAppOrSystem(serviceProvider, allowDeferredReference, mustReturnDeferredResourceReference);

            if (val == null)
            {
                val = DependencyProperty.UnsetValue;
            }

            if (mustReturnDeferredResourceReference)
            {
                if (!(val is DeferredResourceReference))
                {
                    val = new DeferredResourceReferenceHolder(ResourceKey, val);
                }
            }
            return(val);
        }
コード例 #2
0
        // Token: 0x06000866 RID: 2150 RVA: 0x0001B70C File Offset: 0x0001990C
        internal object FindResourceInDeferredContent(IServiceProvider serviceProvider, bool allowDeferredReference, bool mustReturnDeferredResourceReference)
        {
            ResourceDictionary resourceDictionary = this.FindTheResourceDictionary(serviceProvider, true);
            object             obj = DependencyProperty.UnsetValue;

            if (resourceDictionary != null)
            {
                obj = resourceDictionary.Lookup(this.ResourceKey, allowDeferredReference, mustReturnDeferredResourceReference, false);
            }
            if (mustReturnDeferredResourceReference && obj == DependencyProperty.UnsetValue)
            {
                obj = new DeferredResourceReferenceHolder(this.ResourceKey, obj);
            }
            return(obj);
        }
コード例 #3
0
        internal object FindResourceInDeferredContent(IServiceProvider serviceProvider, bool allowDeferredReference, bool mustReturnDeferredResourceReference)
        {
            ResourceDictionary dictionaryWithKey = FindTheResourceDictionary(serviceProvider, /* isDeferredContentSearch */ true);
            object             value             = DependencyProperty.UnsetValue;

            if (dictionaryWithKey != null)
            {
                value = dictionaryWithKey.Lookup(ResourceKey, allowDeferredReference, mustReturnDeferredResourceReference, canCacheAsThemeResource: false);
            }
            if (mustReturnDeferredResourceReference && value == DependencyProperty.UnsetValue)
            {
                value = new DeferredResourceReferenceHolder(ResourceKey, value);
            }
            return(value);
        }
コード例 #4
0
        // Token: 0x06000868 RID: 2152 RVA: 0x0001B78C File Offset: 0x0001998C
        private object FindResourceInEnviroment(IServiceProvider serviceProvider, bool allowDeferredReference, bool mustReturnDeferredResourceReference)
        {
            ResourceDictionary resourceDictionary = this.FindTheResourceDictionary(serviceProvider, false);

            if (resourceDictionary != null)
            {
                return(resourceDictionary.Lookup(this.ResourceKey, allowDeferredReference, mustReturnDeferredResourceReference, false));
            }
            object obj = this.FindResourceInAppOrSystem(serviceProvider, allowDeferredReference, mustReturnDeferredResourceReference);

            if (obj == null)
            {
                obj = DependencyProperty.UnsetValue;
            }
            if (mustReturnDeferredResourceReference && !(obj is DeferredResourceReference))
            {
                obj = new DeferredResourceReferenceHolder(this.ResourceKey, obj);
            }
            return(obj);
        }
コード例 #5
0
ファイル: SystemResources.cs プロジェクト: sjyanxin/WPFSource
        private static bool FindCachedResource(object key, ref object resource, bool mustReturnDeferredResourceReference)
        { 
            // reading the cache is lock free

            resource = _resourceCache[key];
            bool found = (resource != null); 

            if (resource == _specialNull) 
            { 
                // We cached a null, set it to a real null
                resource = null; 
            }
            else
            {
                DispatcherObject dispatcherObject = resource as DispatcherObject; 
                if (dispatcherObject != null)
                { 
                    // The current thread may not have access to this object. 
                    dispatcherObject.VerifyAccess();
                } 
            }

            if (found && mustReturnDeferredResourceReference)
            { 
                resource = new DeferredResourceReferenceHolder(key, resource);
            } 
 
            return found;
        } 
コード例 #6
0
ファイル: SystemResources.cs プロジェクト: sjyanxin/WPFSource
        internal static object FindResourceInternal(object key, bool allowDeferredResourceReference, bool mustReturnDeferredResourceReference)
        {
            // Ensure that resource changes on this thread can be heard and handled
            EnsureResourceChangeListener(); 

            object resource = null; 
            Type typeKey = null; 
            ResourceKey resourceKey = null;
 
            bool isTraceEnabled = EventTrace.IsEnabled(EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose);

            // System resource keys can only be of type Type or of type ResourceKey
            typeKey = key as Type; 
            resourceKey = (typeKey == null) ? (key as ResourceKey) : null;
 
            if (isTraceEnabled) 
            {
                EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientResourceFindBegin, 
                                                    EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose,
                                                    (key == null) ? "null" : key.ToString());
            }
 

            if ((typeKey == null) && (resourceKey == null)) 
            { 
                // Not a valid key
                if (isTraceEnabled) 
                {
                    EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientResourceFindEnd, EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose);
                }
                return null; 
            }
 
            // Check if the value was already cached 
            if (!FindCachedResource(key, ref resource, mustReturnDeferredResourceReference))
            { 
                // Cache miss, do a lookup
                if (isTraceEnabled)
                {
                    EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientResourceCacheMiss, EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose); 
                }
 
                lock (ThemeDictionaryLock) 
                {
                    bool canCache = true; 
                    SystemResourceKey sysKey = (resourceKey != null) ? resourceKey as SystemResourceKey : null;
                    if (sysKey != null)
                    {
                        // Check the list of system metrics 
                        if (!mustReturnDeferredResourceReference)
                        { 
                            resource = sysKey.Resource; 
                        }
                        else 
                        {
                            resource = new DeferredResourceReferenceHolder(sysKey, sysKey.Resource);
                        }
                        if (isTraceEnabled) 
                        {
                            EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientResourceStock, EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose, sysKey.ToString()); 
                        } 
                    }
                    else 
                    {
                        // Do a dictionary lookup
                        resource = FindDictionaryResource(key, typeKey, resourceKey, isTraceEnabled, allowDeferredResourceReference, mustReturnDeferredResourceReference, out canCache);
                    } 

                    if ((canCache && !allowDeferredResourceReference) || resource == null) 
                    { 
                        // Cache the resource
                        CacheResource(key, resource, isTraceEnabled); 
                    }
                }
            }
 
            if (isTraceEnabled)
            { 
                EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientResourceFindEnd, EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose); 
            }
 
            return resource;
        }
コード例 #7
0
        private object FindResourceInEnviroment(IServiceProvider serviceProvider, 
                                                bool allowDeferredReference,
                                                bool mustReturnDeferredResourceReference)
        {
            ResourceDictionary dictionaryWithKey = FindTheResourceDictionary(serviceProvider, /* isDeferredContentSearch */ false);

            if (dictionaryWithKey != null)
            {
                object value = dictionaryWithKey.Lookup(ResourceKey, allowDeferredReference, mustReturnDeferredResourceReference, canCacheAsThemeResource:false);
                return value;
            }

            // Look at app or themes
            object val = FindResourceInAppOrSystem(serviceProvider, allowDeferredReference, mustReturnDeferredResourceReference);
            if (val == null)
            {
                val = DependencyProperty.UnsetValue;
            }

            if (mustReturnDeferredResourceReference)
            {
                if (!(val is DeferredResourceReference))
                {
                    val = new DeferredResourceReferenceHolder(ResourceKey, val);
                }
            }
            return val;
        }
コード例 #8
0
        internal object FindResourceInDeferredContent(IServiceProvider serviceProvider, bool allowDeferredReference, bool mustReturnDeferredResourceReference)
        {
            ResourceDictionary dictionaryWithKey = FindTheResourceDictionary(serviceProvider, /* isDeferredContentSearch */ true);
            object value = DependencyProperty.UnsetValue;

            if (dictionaryWithKey != null)
            {
                value = dictionaryWithKey.Lookup(ResourceKey, allowDeferredReference, mustReturnDeferredResourceReference, canCacheAsThemeResource:false);
            }
            if (mustReturnDeferredResourceReference && value == DependencyProperty.UnsetValue)
            {
                value = new DeferredResourceReferenceHolder(ResourceKey, value);
            }
            return value;
        }
コード例 #9
0
        // Given a key, find object in the parser stack that may hold a 
        // ResourceDictionary and search for an object keyed by that key.
        internal object FindResourceInParentChain( 
            object  resourceNameObject, 
            bool    allowDeferredResourceReference,
            bool    mustReturnDeferredResourceReference) 
        {
            // Try the parser stack first.
            object resource = FindResourceInParserStack(resourceNameObject, allowDeferredResourceReference, mustReturnDeferredResourceReference);
 
            if (resource == DependencyProperty.UnsetValue)
            { 
                // If we get to here, we've either walked off the top of the reader stack, or haven't 
                // found a value on an element that is in the tree.  In that case, give the RootElement
                // and the parent held in the parser context one last try.  This would occur if the 
                // parser is used for literal content that did not contain a DependencyObject tree.
                resource = FindResourceInRootOrAppOrTheme(resourceNameObject, allowDeferredResourceReference, mustReturnDeferredResourceReference);
            }
 
            if (resource == DependencyProperty.UnsetValue && mustReturnDeferredResourceReference)
            { 
                resource = new DeferredResourceReferenceHolder(resourceNameObject, DependencyProperty.UnsetValue); 
            }
 
            return resource;
        }