Пример #1
0
        // Token: 0x06000C6A RID: 3178 RVA: 0x0002E850 File Offset: 0x0002CA50
        private static void InvalidateResourceReferences(DependencyObject d, ResourcesChangeInfo info)
        {
            LocalValueEnumerator localValueEnumerator = d.GetLocalValueEnumerator();
            int count = localValueEnumerator.Count;

            if (count > 0)
            {
                ResourceReferenceExpression[] array = new ResourceReferenceExpression[count];
                int num = 0;
                while (localValueEnumerator.MoveNext())
                {
                    LocalValueEntry             localValueEntry             = localValueEnumerator.Current;
                    ResourceReferenceExpression resourceReferenceExpression = localValueEntry.Value as ResourceReferenceExpression;
                    if (resourceReferenceExpression != null && info.Contains(resourceReferenceExpression.ResourceKey, false))
                    {
                        array[num] = resourceReferenceExpression;
                        num++;
                    }
                }
                ResourcesChangedEventArgs e = new ResourcesChangedEventArgs(info);
                for (int i = 0; i < num; i++)
                {
                    array[i].InvalidateExpressionValue(d, e);
                }
            }
        }
Пример #2
0
 private void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
 {
     if (e.Contains(resourceKey))
     {
         observableValue.BaseValue = GetResourceValue();
     }
 }
        // Token: 0x0600087C RID: 2172 RVA: 0x0001BB60 File Offset: 0x00019D60
        internal void InvalidateExpressionValue(object sender, EventArgs e)
        {
            if (this._targetObject == null)
            {
                return;
            }
            ResourcesChangedEventArgs resourcesChangedEventArgs = e as ResourcesChangedEventArgs;

            if (resourcesChangedEventArgs != null)
            {
                if (!resourcesChangedEventArgs.Info.IsTreeChange)
                {
                    this.InvalidateCacheValue();
                }
                else
                {
                    this.InvalidateMentorCache();
                }
            }
            else
            {
                this.InvalidateMentorCache();
            }
            this.InvalidateTargetProperty(sender, e);
        }
Пример #4
0
        public void Clear()
        {
            ResourcesChangedEventArgs e = ResourcesChangedEventArgs.FromKeyCollection(dictionary.Keys.ToArray());

            dictionary.Clear();
            ResourcesChanged.Raise(this, e);
        }
Пример #5
0
        public bool Remove(object key)
        {
            if (dictionary.Remove(key))
            {
                ResourcesChanged.Raise(this, ResourcesChangedEventArgs.FromKey(key));
                return(true);
            }

            return(false);
        }
Пример #6
0
        protected virtual void OnResourcesChanged(ResourcesChangedEventArgs e)
        {
            if (DefaultStyleKey == null || !e.Contains(DefaultStyleKey))
            {
                return;
            }

            object value;

            if (!TryGetResource(DefaultStyleKey, out value))
            {
                value = null;
            }

            SetValue(StyleProperty, value, BaseValueSource.Default);
        }
Пример #7
0
        private void OnMergedDictionariesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            foreach (ResourceDictionary dictionary in e.OldItems)
            {
                dictionary.ResourcesChanged -= OnMergeDictionaryResourcesChanged;
            }

            foreach (ResourceDictionary dictionary in e.NewItems)
            {
                dictionary.ResourcesChanged += OnMergeDictionaryResourcesChanged;
            }

            if (e.Action != NotifyCollectionChangedAction.Move)
            {
                IEnumerable <object> keys = e.OldItems.Concat(e.NewItems).Cast <ResourceDictionary>().SelectMany(GetMergedDictionariesKeys);
                ResourcesChanged.Raise(this, ResourcesChangedEventArgs.FromKeyCollection(keys));
            }
        }
        /// <summary>
        ///     This event handler is called to invalidate the cached value held in
        ///     this expression. This is called under the following 3 scenarios
        ///     1. InheritanceContext changes
        ///     2. Logical tree changes
        ///     3. ResourceDictionary changes
        /// </summary>
        internal void InvalidateExpressionValue(object sender, EventArgs e)
        {
            // VS has a scenario where a TreeWalk invalidates all reference expressions on a DependencyObject.
            // If there is a dependency between RRE's,
            // invalidating one RRE could cause _targetObject to be null on the other RRE. Hence this check.
            if (_targetObject == null)
            {
                return;
            }

            ResourcesChangedEventArgs args = e as ResourcesChangedEventArgs;

            if (args != null)
            {
                ResourcesChangeInfo info = args.Info;
                if (!info.IsTreeChange)
                {
                    // This will happen when
                    // 1. Theme changes
                    // 2. Entire ResourceDictionary in the ancestry changes
                    // 3. Single entry in a ResourceDictionary in the ancestry is changed
                    // In all of the above cases it is sufficient to re-evaluate the cache
                    // value alone. The mentor relation ships stay the same.
                    InvalidateCacheValue();
                }
                else
                {
                    // This is the case of a logical tree change and hence we need to
                    // re-evaluate both the mentor and the cached value.
                    InvalidateMentorCache();
                }
            }
            else
            {
                // There is no information provided by the EventArgs. Hence we
                // pessimistically invalidate both the mentor and the cached value.
                // This code path will execute when the InheritanceContext changes.
                InvalidateMentorCache();
            }

            InvalidateTargetProperty(sender, e);
        }
Пример #9
0
 protected virtual void OnResourcesChanged(ResourcesChangedEventArgs e)
 {
     resourcesCache.Clear();
     SetValue(StyleProperty, GetDefaultStyle(), BaseValueSource.Default);
 }
Пример #10
0
 private void RaiseResourcesChanged(ResourcesChangedEventArgs e)
 {
     OnResourcesChanged(e);
     ResourcesChanged.Raise(this, e);
 }
Пример #11
0
 private void OnResourceDictionaryChanged(object sender, ResourcesChangedEventArgs e)
 {
     RaiseResourcesChanged(e);
 }
Пример #12
0
 private void OnParentResourcesChanged(object sender, ResourcesChangedEventArgs e)
 {
     RaiseResourcesChanged(e);
 }
Пример #13
0
 private void OnParentResourcesChanged(object sender, ResourcesChangedEventArgs e)
 {
     RaiseResourcesChanged(e);
 }
 private void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
 {
     if (e.Contains(resourceKey))
     {
         observableValue.Value = GetResourceValue();
     }
 }
Пример #15
0
 private void OnMergeDictionaryResourcesChanged(object sender, ResourcesChangedEventArgs e)
 {
     ResourcesChanged.Raise(this, e);
 }
Пример #16
0
 public void Add(object key, object value)
 {
     dictionary[key] = value;
     ResourcesChanged.Raise(this, ResourcesChangedEventArgs.FromKey(key));
 }
Пример #17
0
 private void RaiseResourcesChanged(ResourcesChangedEventArgs e)
 {
     OnResourcesChanged(e);
     ResourcesChanged.Raise(this, e);
 }
Пример #18
0
 private void OnResourceDictionaryChanged(object sender, ResourcesChangedEventArgs e)
 {
     RaiseResourcesChanged(e);
 }
Пример #19
0
 private void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
 {
     ResourcesChanged.Raise(this, e);
 }
Пример #20
0
 private void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
 {
     ResourcesChanged.Raise(this, e);
 }
Пример #21
0
        /// <summary>
        ///     Invalidates all properties that reference a resource. 
        ///     NOTE: The return value for this method indicates whether or not a ResourceReference 
        ///     property was found on the given object. This is to take care of the special case when
        ///     programmatically changing a ResourceReference property value does not reflect on the 
        ///     bit stored on FrameworkElement or FrameworkContentElement that indicates whether
        ///     the current instance has ResourceReference values set on it. This current operation
        ///     is a point of synchronization for this flag.
        /// </summary> 
        /// <remarks>
        ///     This methods is called when one of the following operations occurred. 
        ///     1) A tree change 
        ///     2) A resource dictionary change
        ///     3) A modification to a single entry in a dictionary 
        /// </remarks>
        private static void InvalidateResourceReferences(
            DependencyObject    d,
            ResourcesChangeInfo info) 
        {
            Debug.Assert(d != null, "Must have non-null current node"); 
 
            // Find properties that have resource reference value
            LocalValueEnumerator localValues = d.GetLocalValueEnumerator(); 
            int localValuesCount = localValues.Count;

            if (localValuesCount > 0)
            { 
                // Resource reference invalidation involves two passes - first to
                // pick out what we need to invalidate, and the second to do the 
                // actual invalidation.  This is needed because LocalValueEnumerator 
                // will halt if any local values have changed, which can happen
                // depending on what people are doing in their OnPropertyChanged 
                // callback.

                // The following array is used to track the ResourceReferenceExpressions that we find
                ResourceReferenceExpression[] resources = new ResourceReferenceExpression[localValuesCount]; 
                int invalidationCount = 0;
 
                // Pass #1 - find what needs invalidation 
                while (localValues.MoveNext())
                { 
                    // Is this a resource reference?
                    ResourceReferenceExpression resource = localValues.Current.Value as ResourceReferenceExpression;
                    if (resource != null)
                    { 
                        // Record this property if it is referring
                        // to a resource that is being changed 
                        if (info.Contains(resource.ResourceKey, false /*isImplicitStyleKey*/)) 
                        {
                            resources[invalidationCount]  = resource; 
                            invalidationCount++;
                        }
                    }
                } 

                ResourcesChangedEventArgs args = new ResourcesChangedEventArgs(info); 
 
                // Pass #2 - actually make the invalidation calls, now that we're
                // outside the LocalValueEnumerator. 
                for (int i = 0; i < invalidationCount; i++)
                {
                    // Let the resource reference throw away its cache
                    // and invalidate the property in which it's held 
                    // re-evaluate expression
                    resources[i].InvalidateExpressionValue(d, args); 
                } 
            }
        } 
Пример #22
0
 protected virtual void OnResourcesChanged(ResourcesChangedEventArgs e)
 {
     resourcesCache.Clear();
     SetValue(StyleProperty, GetDefaultStyle(), BaseValueSource.Default);
 }