// // This method // 1. Adds or removes per-instance state on the container/child (push model) // 2. Processes a single value that needs per-instance storage // internal static void ProcessInstanceValue( DependencyObject target, int childIndex, HybridDictionary instanceValues, DependencyProperty dp, int i, bool apply) { // If we get this far, it's because there's a value // in the property value list of an active style that requires // per-instance storage. The initialization (CreateInstaceData) // should have created the InstanceValues hashtable by now. Debug.Assert(instanceValues != null, "InstanceValues hashtable should have been created at initialization time."); InstanceValueKey key = new InstanceValueKey(childIndex, dp.GlobalIndex, i); if (apply) { // Store a sentinel value in per-instance StyleData. // The actual value is created only on demand. instanceValues[key] = NotYetApplied; } else { // Remove the instance value from the table object value = instanceValues[key]; instanceValues.Remove(key); Expression expr; Freezable freezable; if ((expr = value as Expression)!= null) { // if the instance value is an expression, detach it expr.OnDetach(target, dp); } else if ((freezable = value as Freezable)!= null) { // if the instance value is a Freezable, remove its // inheritance context target.RemoveSelfAsInheritanceContext(freezable, dp); } } }
// // This method // 1. Retrieves an instance value from per-instance StyleData. // 2. Creates the StyleData if this is the first request. // internal static object GetInstanceValue( UncommonField<HybridDictionary []> dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, int childIndex, DependencyProperty dp, int i, ref EffectiveValueEntry entry) { object rawValue = entry.Value; DependencyObject child = null; FrameworkElement feContainer; FrameworkContentElement fceContainer; Helper.DowncastToFEorFCE(container, out feContainer, out fceContainer, true); HybridDictionary[] styleData = (dataField != null) ? dataField.GetValue(container) : null; HybridDictionary instanceValues = (styleData != null) ? styleData[(int)InstanceStyleData.InstanceValues] : null; InstanceValueKey key = new InstanceValueKey(childIndex, dp.GlobalIndex, i); object value = (instanceValues != null)? instanceValues[key] : null; bool isRequestingExpression = (feChild != null) ? feChild.IsRequestingExpression : fceChild.IsRequestingExpression; if (value == null) { value = NotYetApplied; } // if the value is a detached expression, replace it with a new one Expression expr = value as Expression; if (expr != null && expr.HasBeenDetached) { value = NotYetApplied; } // if this is the first request, create the value if (value == NotYetApplied) { child = feChild; if (child == null) child = fceChild; MarkupExtension me; Freezable freezable; if ((me = rawValue as MarkupExtension) != null) { // exception: if the child is not yet initialized and the request // is for an expression, don't create the value. This gives the parser // a chance to set local values, to override the style-defined values. if (isRequestingExpression) { bool isInitialized = (feChild != null) ? feChild.IsInitialized : fceChild.IsInitialized; if (!isInitialized) { return DependencyProperty.UnsetValue; } } ProvideValueServiceProvider provideValueServiceProvider = new ProvideValueServiceProvider(); provideValueServiceProvider.SetData( child, dp ); value = me.ProvideValue(provideValueServiceProvider); } else if ((freezable = rawValue as Freezable) != null) { value = freezable.Clone(); child.ProvideSelfAsInheritanceContext(value, dp); } // store it in per-instance StyleData (even if it's DependencyProperty.UnsetValue) Debug.Assert(value != NotYetApplied, "attempt to retrieve instance value that was never set"); instanceValues[key] = value; if (value != DependencyProperty.UnsetValue) { expr = value as Expression; // if the instance value is an expression, attach it if (expr != null) { expr.OnAttach(child, dp); } } } // if the value is an Expression (and we're being asked for the real value), // delegate to the expression. if (expr != null) { if (!isRequestingExpression) { if (child == null) { child = feChild; if (child == null) child = fceChild; } entry.ResetValue(DependencyObject.ExpressionInAlternativeStore, true); entry.SetExpressionValue(expr.GetValue(child, dp), DependencyObject.ExpressionInAlternativeStore); } else { entry.Value = value; } } else { entry.Value = value; } return value; }
// Token: 0x06000967 RID: 2407 RVA: 0x00020FB0 File Offset: 0x0001F1B0 public override bool Equals(object o) { InstanceValueKey instanceValueKey = o as InstanceValueKey; return(instanceValueKey != null && (this._childIndex == instanceValueKey._childIndex && this._dpIndex == instanceValueKey._dpIndex) && this._index == instanceValueKey._index); }