internal void SetValueCommon(DependencyProperty dependencyProperty, object value, PropertyMetadata metadata, bool shouldCallSetValueOverrideIfExists) { if (dependencyProperty.DefaultMetadata.IsReadOnly) { throw new ArgumentException(SR.GetString("Error_DPReadOnly"), "dependencyProperty"); } if (value is ActivityBind) { throw new ArgumentException(SR.GetString("Error_DPSetValueBind"), "value"); } if (dependencyProperty.IsEvent) { throw new ArgumentException(SR.GetString("Error_DPSetValueHandler"), "dependencyProperty"); } if (!dependencyProperty.IsAttached && !dependencyProperty.OwnerType.IsAssignableFrom(base.GetType())) { throw new InvalidOperationException(SR.GetString("Error_InvalidDependencyProperty", new object[] { base.GetType().FullName, dependencyProperty.Name, dependencyProperty.OwnerType.FullName })); } if ((!this.DesignMode && dependencyProperty.DefaultMetadata.IsMetaProperty) && (dependencyProperty != ConditionTypeConverter.DeclarativeConditionDynamicProp)) { throw new InvalidOperationException(SR.GetString("Error_CanNotChangeAtRuntime")); } if ((value != null) && !dependencyProperty.PropertyType.IsAssignableFrom(value.GetType())) { throw new ArgumentException(SR.GetString("Error_DynamicPropertyTypeValueMismatch", new object[] { dependencyProperty.PropertyType.FullName, dependencyProperty.Name, value.GetType().FullName }), "value"); } if (shouldCallSetValueOverrideIfExists && (metadata.SetValueOverride != null)) { metadata.SetValueOverride(this, value); } else { IDictionary <DependencyProperty, object> metaProperties = null; if (dependencyProperty.DefaultMetadata.IsMetaProperty) { metaProperties = this.metaProperties; } else { metaProperties = this.DependencyPropertyValues; } object obj2 = null; if ((this.metaProperties != null) && this.metaProperties.ContainsKey(dependencyProperty)) { obj2 = this.metaProperties[dependencyProperty]; if (this.DesignMode) { this.metaProperties.Remove(dependencyProperty); } } if (!this.DesignMode && (obj2 is ActivityBind)) { this.SetBoundValue((ActivityBind)obj2, value); } else if (metaProperties.ContainsKey(dependencyProperty)) { metaProperties[dependencyProperty] = value; } else { metaProperties.Add(dependencyProperty, value); } } }
internal void SetValueCommon(DependencyProperty dependencyProperty, object value, PropertyMetadata metadata, bool shouldCallSetValueOverrideIfExists) { if (dependencyProperty.DefaultMetadata.IsReadOnly) { throw new ArgumentException(SR.GetString(SR.Error_DPReadOnly), "dependencyProperty"); } if (value is ActivityBind) { throw new ArgumentException(SR.GetString(SR.Error_DPSetValueBind), "value"); } if (dependencyProperty.IsEvent) { throw new ArgumentException(SR.GetString(SR.Error_DPSetValueHandler), "dependencyProperty"); } if (!dependencyProperty.IsAttached && !dependencyProperty.OwnerType.IsAssignableFrom(this.GetType())) { throw new InvalidOperationException(SR.GetString(SR.Error_InvalidDependencyProperty, this.GetType().FullName, dependencyProperty.Name, dependencyProperty.OwnerType.FullName)); } //ok, the default case // Work around Declarative conditions if (!this.DesignMode && (dependencyProperty.DefaultMetadata.IsMetaProperty && dependencyProperty != Design.ConditionTypeConverter.DeclarativeConditionDynamicProp)) { throw new InvalidOperationException(SR.GetString(SR.Error_CanNotChangeAtRuntime)); } if (value != null && !dependencyProperty.PropertyType.IsAssignableFrom(value.GetType())) { throw new ArgumentException(SR.GetString(SR.Error_DynamicPropertyTypeValueMismatch, new object[] { dependencyProperty.PropertyType.FullName, dependencyProperty.Name, value.GetType().FullName }), "value"); } // Set type-specific metadata for this property if the delegate was specified if (shouldCallSetValueOverrideIfExists && metadata.SetValueOverride != null) { metadata.SetValueOverride(this, value); return; } //Even if the DependencyProperty is an instance property if its value is of type bind //we store it in MetaProperties, We need this to make bind work IDictionary <DependencyProperty, object> properties = null; if (dependencyProperty.DefaultMetadata.IsMetaProperty) { properties = this.metaProperties; } else { properties = this.DependencyPropertyValues; } object oldMetaValue = null; if (this.metaProperties != null && this.metaProperties.ContainsKey(dependencyProperty)) { oldMetaValue = this.metaProperties[dependencyProperty]; if (this.DesignMode) { this.metaProperties.Remove(dependencyProperty); } } if (!this.DesignMode && (oldMetaValue is ActivityBind)) { this.SetBoundValue((ActivityBind)oldMetaValue, value); } else { if (properties.ContainsKey(dependencyProperty)) { properties[dependencyProperty] = value; } else { properties.Add(dependencyProperty, value); } } }