コード例 #1
0
        /// <summary>
        /// Fetches the resource corresponding to the given key from this dictionary. 
        /// Returns a DeferredResourceReference if the object has not been inflated yet.
        /// </summary>
        internal object FetchResource(
            object      resourceKey, 
            bool        allowDeferredResourceReference,
            bool        mustReturnDeferredResourceReference, 
            out bool    canCache) 
        {
            Debug.Assert(resourceKey != null, "ResourceKey cannot be null"); 

            if (allowDeferredResourceReference)
            {
                if (ContainsBamlObjectFactory(resourceKey) || 
                    (mustReturnDeferredResourceReference && Contains(resourceKey)))
                { 
                    canCache = false; 

                    DeferredResourceReference deferredResourceReference; 
                    if (!IsThemeDictionary)
                    {
                        if (_ownerApps != null)
                        { 
                            deferredResourceReference = new DeferredAppResourceReference(this, resourceKey);
                        } 
                        else 
                        {
                            deferredResourceReference = new DeferredResourceReference(this, resourceKey); 
                        }

                        // Cache the deferredResourceReference so that it can be validated
                        // in case of a dictionary change prior to its inflation 
                        if (_deferredResourceReferences == null)
                        { 
                            _deferredResourceReferences = new WeakReferenceList(); 
                        }
 
                        _deferredResourceReferences.Add( deferredResourceReference, true /*SkipFind*/);
                    }
                    else
                    { 
                        deferredResourceReference = new DeferredThemeResourceReference(this, resourceKey);
                    } 
 
                    return deferredResourceReference;
                } 
            }

            return GetValue(resourceKey, out canCache);
        } 
コード例 #2
0
ファイル: SystemResources.cs プロジェクト: sjyanxin/WPFSource
 internal virtual void AddInflatedListener(ResourceReferenceExpression listener)
 {
     if (_inflatedList == null)
     { 
         _inflatedList = new WeakReferenceList(this);
     } 
     _inflatedList.Add(listener); 
 }
コード例 #3
0
        // Add an owner for this dictionary
        internal void AddOwner(DispatcherObject owner) 
        {
            if (_inheritanceContext == null) 
            { 
                // the first owner gets to be the InheritanceContext for
                // all the values in the dictionary that want one. 
                _inheritanceContext = owner as DependencyObject;

                if (_inheritanceContext != null)
                { 
                    // set InheritanceContext for the existing values
                    AddInheritanceContextToValues(); 
                } 
                else
                { 
                    // if the first owner is ineligible, use a dummy
                    _inheritanceContext = new DependencyObject();
                    _inheritanceContext.DetachFromDispatcher();
 
                    // do not call AddInheritanceContextToValues -
                    // the owner is an Application, and we'll be 
                    // calling SealValues soon, which takes care 
                    // of InheritanceContext as well
                } 

            }

            FrameworkElement fe = owner as FrameworkElement; 
            if (fe != null)
            { 
                if (_ownerFEs == null) 
                {
                    _ownerFEs = new WeakReferenceList(1); 
                }
                else if (_ownerFEs.Contains(fe) && ContainsCycle(this))
                {
                    throw new InvalidOperationException(SR.Get(SRID.ResourceDictionaryInvalidMergedDictionary)); 
                }
 
                // Propagate the HasImplicitStyles flag to the new owner 
                if (HasImplicitStyles)
                { 
                    fe.ShouldLookupImplicitStyles = true;
                }

                _ownerFEs.Add(fe); 
            }
            else 
            { 
                FrameworkContentElement fce = owner as FrameworkContentElement;
                if (fce != null) 
                {
                    if (_ownerFCEs == null)
                    {
                        _ownerFCEs = new WeakReferenceList(1); 
                    }
                    else if (_ownerFCEs.Contains(fce) && ContainsCycle(this)) 
                    { 
                        throw new InvalidOperationException(SR.Get(SRID.ResourceDictionaryInvalidMergedDictionary));
                    } 

                    // Propagate the HasImplicitStyles flag to the new owner
                    if (HasImplicitStyles)
                    { 
                        fce.ShouldLookupImplicitStyles = true;
                    } 
 
                    _ownerFCEs.Add(fce);
                } 
                else
                {
                    Application app = owner as Application;
                    if (app != null) 
                    {
                        if (_ownerApps == null) 
                        { 
                            _ownerApps = new WeakReferenceList(1);
                        } 
                        else if (_ownerApps.Contains(app) && ContainsCycle(this))
                        {
                            throw new InvalidOperationException(SR.Get(SRID.ResourceDictionaryInvalidMergedDictionary));
                        } 

                        // Propagate the HasImplicitStyles flag to the new owner 
                        if (HasImplicitStyles) 
                        {
                            app.HasImplicitStylesInResources = true; 
                        }

                        _ownerApps.Add(app);
 
                        // An Application ResourceDictionary can be accessed across threads
                        CanBeAccessedAcrossThreads = true; 
 
                        // Seal all the styles and templates in this app dictionary
                        SealValues(); 
                    }
                }
            }
 
            AddOwnerToAllMergedDictionaries(owner);
 
            // This dictionary will be marked initialized if no one has called BeginInit on it. 
            // This is done now because having an owner is like a parenting operation for the dictionary.
            TryInitialize(); 
        }