internal DependencyPropertyChangedEventArgs( DependencyProperty property, PropertyMetadata metadata, bool isAValueChange, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, OperationType operationType) { _property = property; _metadata = metadata; _oldEntry = oldEntry; _newEntry = newEntry; _flags = 0; _operationType = operationType; IsAValueChange = isAValueChange; // This is when a mutable default is promoted to a local value. On this operation mutable default // value acquires a freezable context. However this value promotion operation is triggered // whenever there has been a sub property change to the mutable default. Eg. Adding a TextEffect // to a TextEffectCollection instance which is the mutable default. Since we missed the sub property // change due to this add, we flip the IsASubPropertyChange bit on the following change caused by // the value promotion to coalesce these operations. IsASubPropertyChange = (operationType == OperationType.ChangeMutableDefaultValue); }
static TestUserControl() { PropertyMetadata metaData; metaData = new PropertyMetadata(Colors.Red); ColorProperty = DependencyProperty.Register("Color", typeof(Color), typeof(TestUserControl),metaData); }
static ColorPick() { PropertyMetadata metaData; metaData = new PropertyMetadata(Colors.Red); ColorProperty = DependencyProperty.Register("Color", typeof(Color), typeof(ColorPick),metaData); }
static DiagramLabel() { var fontFamilyMd = new PropertyMetadata(new FontFamily("Arial"), OnFontFamilyChanged); FontFamilyProperty = DependencyProperty.Register("FontFamily", typeof (FontFamily), typeof (DiagramLabel), fontFamilyMd); var fontWeightMd = new PropertyMetadata(FontWeights.Normal, OnFontWeightChanged); FontWeightProperty = DependencyProperty.Register("FontWeight", typeof (FontWeight), typeof (DiagramLabel), fontWeightMd); const double defaultSize = 11; var fontSizeMd = new PropertyMetadata(defaultSize, OnFontSizeChanged); FontSizeProperty = DependencyProperty.Register("FontSize", typeof (double), typeof (DiagramLabel), fontSizeMd); var fontStyleMd = new PropertyMetadata(FontStyles.Normal, OnFontStyleChanged); FontStyleProperty = DependencyProperty.Register("FontStyle", typeof (FontStyle), typeof (DiagramLabel), fontStyleMd); var fontStretchMd = new PropertyMetadata(FontStretches.Normal, OnFontStretchChanged); FontStretchProperty = DependencyProperty.Register("FontStretch", typeof (FontStretch), typeof (DiagramLabel), fontStretchMd); var foregroundMd = new PropertyMetadata(new SolidColorBrush(Colors.Black), OnForegroundChanged); ForegroundProperty = DependencyProperty.Register("Foreground", typeof (Brush), typeof (DiagramLabel), foregroundMd); var relativePosMd = new PropertyMetadata(new Point(0, 0), OnRelativePositionChanged); RelativePositionProperty = DependencyProperty.Register("RelativePosition", typeof (Point), typeof (DiagramLabel), relativePosMd); var textMd = new PropertyMetadata("", OnTextChanged); TextProperty = DependencyProperty.Register("Text", typeof (String), typeof (DiagramLabel), textMd); }
private static PropertyMetadata GetCurrentPageIndexPropetyMetadata() { PropertyMetadata pm = new PropertyMetadata(); pm.DefaultValue = 1; pm.PropertyChangedCallback = new PropertyChangedCallback(CurrentPageIndexPropertyChanged); return pm; }
public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata) { if (typeMetadata == null) typeMetadata = new PropertyMetadata (); OverrideMetadata (ownerType, typeMetadata); // MS seems to always return the same DependencyProperty return this; }
static EyeCandy() { //register attached dependency property var metadata = new PropertyMetadata((ImageSource)null); ImageProperty = DependencyProperty.RegisterAttached("Image", typeof(ImageSource), typeof(EyeCandy), metadata); }
/// <summary> /// Override the metadata of a property that is already secured with /// this key. /// </summary> public void OverrideMetadata( Type forType, PropertyMetadata typeMetadata ) { if( _dp == null ) { throw new InvalidOperationException(); } _dp.OverrideMetadata( forType, typeMetadata, this ); }
static GameManagerProperties() { PropertyChangedCallback dockingManagerChanged = new PropertyChangedCallback(OnDockingManagerChanged); PropertyMetadata dockingManagerMetadata = new PropertyMetadata(null, dockingManagerChanged); DockingManagerProperty = DependencyProperty.RegisterAttached("DockingManager", typeof(DockingManager), typeof(GameManagerProperties), dockingManagerMetadata); }
private DependencyProperty(DependencyProperty property, PropertyMetadata defaultMetadata) { _defaultMetadata = defaultMetadata; _name = property._name; _ownerType = property._ownerType; _propertyType = property._propertyType; _validateValueCallback = property._validateValueCallback; _properties[_name + _ownerType] = this; }
private DependencyProperty (bool isAttached, string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback) { IsAttached = isAttached; DefaultMetadata = (defaultMetadata == null ? new PropertyMetadata() : defaultMetadata); Name = name; OwnerType = ownerType; PropertyType = propertyType; ValidateValueCallback = validateValueCallback; }
static DiagramEdge() { var sourcePointMd = new PropertyMetadata(new Point(0, 0), OnSourcePointChanged); SourcePointProperty = DependencyProperty.Register("SourcePoint", typeof (Point), typeof (DiagramEdge), sourcePointMd); var destinationPointMd = new PropertyMetadata(new Point(0, 0), OnDestinationPointChanged); DestinationPointProperty = DependencyProperty.Register("DestinationPoint", typeof (Point), typeof (DiagramEdge), destinationPointMd); var anchoringModeMd = new PropertyMetadata(EdgeAnchoringMode.PointToPoint, OnAnchoringModeChanged); AnchoringModeProperty = DependencyProperty.Register("AnchoringMode", typeof (EdgeAnchoringMode), typeof (DiagramEdge), anchoringModeMd); }
static DiagramNode() { var boundsMd = new PropertyMetadata(new Rect(0, 0, 0, 0), OnBoundsChanged); BoundsProperty = DependencyProperty.Register("Bounds", typeof(Rect), typeof(DiagramNode), boundsMd); var radiusXMd = new PropertyMetadata(0.0, OnRadiusXChanged); RadiusXProperty = DependencyProperty.Register("RadiusX", typeof(double), typeof(DiagramNode), radiusXMd); var radiusYMd = new PropertyMetadata(0.0, OnRadiusYChanged); RadiusYProperty = DependencyProperty.Register("RadiusY", typeof(double), typeof(DiagramNode), radiusYMd); }
DependencyProperty ( string propertyName, Type propertyType, Type ownerType, PropertyMetadata metadata ) { this.Name = propertyName; this.PropertyType = propertyType; this.OwnerType = ownerType; this.DefaultMetadata = metadata; }
private DependencyProperty(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback) { _name = name; _propertyType = propertyType; _ownerType = ownerType; _defaultMetadata = defaultMetadata; _validateValueCallback = validateValueCallback; _properties[name + ownerType] = this; }
internal DependencyPropertyChangedEventArgs(DependencyProperty property, PropertyMetadata metadata, object value) { _property = property; _metadata = metadata; _oldEntry = new EffectiveValueEntry(property); _oldEntry.Value = value; _newEntry = _oldEntry; _flags = 0; _operationType = OperationType.Unknown; IsASubPropertyChange = true; }
public FastComboBox() { var propertyMetadata = new PropertyMetadata(OnItemsSource2Changed); ItemsSource2Property = DependencyProperty.Register( "ItemsSource2" , typeof(IEnumerable) , typeof(FastComboBox) , propertyMetadata); DefaultStyleKey = typeof(FastComboBox); }
public void Should_Return_Same_DependencyProperty() { PropertyMetadata metadata1 = new PropertyMetadata("foo"); DependencyProperty dp1 = DependencyProperty.Register( "Should_Return_Same_DependencyProperty", typeof(string), typeof(TestClass1), metadata1); DependencyProperty dp2 = dp1.AddOwner(typeof(TestClass2)); Assert.AreSame(dp1, dp2); }
public void Should_Not_Change_OwnerType() { PropertyMetadata metadata1 = new PropertyMetadata("foo"); DependencyProperty dp = DependencyProperty.Register( "Should_Not_Change_OwnerType", typeof(string), typeof(TestClass1), metadata1); dp.AddOwner(typeof(TestClass2)); Assert.AreEqual(typeof(TestClass1), dp.OwnerType); }
static DiagramItem() { var backgroundMd = new PropertyMetadata(new SolidColorBrush(Colors.Transparent), OnBackgroundChanged); BackgroundProperty = DependencyProperty.Register("Background", typeof(Brush), typeof(DiagramItem), backgroundMd); var borderPenMd = new PropertyMetadata(new Pen(Brushes.Black, 1), OnBorderPenChanged); BorderPenProperty = DependencyProperty.Register("BorderPen", typeof(Pen), typeof(DiagramItem), borderPenMd); var dataMd = new PropertyMetadata(null, OnDataChanged); DataProperty = DependencyProperty.Register("Data", typeof(object), typeof(DiagramItem), dataMd); var userDataMd = new PropertyMetadata(null, OnUserDataChanged); UserDataProperty = DependencyProperty.Register("UserData", typeof(object), typeof(DiagramItem), userDataMd); }
static Diagram() { var xViewOffsetMd = new PropertyMetadata(0.0, OnXViewOffsetChanged); XViewOffsetProperty = DependencyProperty.Register("XViewOffset", typeof(double), typeof(Diagram), xViewOffsetMd); var yViewOffsetMd = new PropertyMetadata(0.0, OnYViewOffsetChanged); YViewOffsetProperty = DependencyProperty.Register("YViewOffset", typeof(double), typeof(Diagram), yViewOffsetMd); var scaleMd = new PropertyMetadata(1.0, OnZoomChanged); ScaleProperty = DependencyProperty.Register("Scale", typeof(double), typeof(Diagram), scaleMd); var scaleFactorMd = new PropertyMetadata(1.1); ScaleFactorProperty = DependencyProperty.Register("ScaleFactor", typeof(double), typeof(Diagram), scaleFactorMd); }
static MainWindow() { var metadata = new PropertyMetadata(new ObservableCollection<long> { 3, 2, 17, 20, 63553547345645653, 34563456314523431, 989956756956978671, 989956756956978673, }); NumbersProperty = DependencyProperty.Register("Numbers", typeof(ObservableCollection<long>), typeof(MainWindow), metadata); }
/// <summary> /// Register a Dependency Property /// </summary> /// <param name="name">Name of property</param> /// <param name="propertyType">Type of the property</param> /// <param name="ownerType">Type that is registering the property</param> /// <param name="typeMetadata">Metadata to use if current type doesn't specify type-specific metadata</param> /// <param name="validateValueCallback">Provides additional value validation outside automatic type validation</param> /// <returns>Dependency Property</returns> public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback) { RegisterParameterValidation(name, propertyType, ownerType); // Register an attached property PropertyMetadata defaultMetadata = null; if (typeMetadata != null && typeMetadata.DefaultValueWasSet()) { defaultMetadata = new PropertyMetadata(typeMetadata.DefaultValue); } DependencyProperty property = RegisterCommon(name, propertyType, ownerType, defaultMetadata, validateValueCallback); if (typeMetadata != null) { // Apply type-specific metadata to owner type only property.OverrideMetadata(ownerType, typeMetadata); } return property; }
//BASE CLASS PROPERTY OVERRIDES /// <summary> /// Registers properties. /// </summary> static TaskbarIcon() { //register change listener for the Visibility property var md = new PropertyMetadata(Visibility.Visible, VisibilityPropertyChanged); VisibilityProperty.OverrideMetadata(typeof (TaskbarIcon), md); //register change listener for the DataContext property md = new FrameworkPropertyMetadata(new PropertyChangedCallback(DataContextPropertyChanged)); DataContextProperty.OverrideMetadata(typeof (TaskbarIcon), md); //register change listener for the ContextMenu property md = new FrameworkPropertyMetadata(new PropertyChangedCallback(ContextMenuPropertyChanged)); ContextMenuProperty.OverrideMetadata(typeof (TaskbarIcon), md); }
/// <summary> /// The common code shared by all variants of ClearValue /// </summary> private void ClearValueCommon(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata) { if (IsSealed) { throw new InvalidOperationException(SR.Get(SRID.ClearOnReadOnlyObjectNotAllowed, this)); } // Get old value EffectiveValueEntry oldEntry = GetValueEntry( entryIndex, dp, metadata, RequestFlags.RawEntry); // Get current local value // (No need to go through read local callback, just checking // for presence of Expression) object current = oldEntry.LocalValue; // Get current expression Expression currentExpr = (oldEntry.IsExpression) ? (current as Expression) : null; // Inform value expression of detachment, if applicable if (currentExpr != null) { // CALLBACK DependencySource[] currentSources = currentExpr.GetSources(); UpdateSourceDependentLists(this, dp, currentSources, currentExpr, false); // Remove // CALLBACK currentExpr.OnDetach(this, dp); currentExpr.MarkDetached(); entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex); } // valuesource == Local && value == UnsetValue indicates that we are clearing the local value EffectiveValueEntry newEntry = new EffectiveValueEntry(dp, BaseValueSourceInternal.Local); // Property is now invalid UpdateEffectiveValue( entryIndex, dp, metadata, oldEntry, ref newEntry, false /* coerceWithDeferredReference */, false /* coerceWithCurrentValue */, OperationType.Unknown); }
public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata metadata = null, ValidateValueCallback validateValueCallback = null) { return(Register(new DependencyPropertyHashKey(ownerType, name), propertyType, metadata, validateValueCallback, true, false)); }
// // This method // 1. Removes the entry if there is one with valueSource >= the specified // internal void UnsetEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata) { if (entryIndex.Found) { RemoveEntry(entryIndex.Index, dp); if (metadata != null && metadata.IsInherited) { InheritableEffectiveValuesCount--; } } }
/// <summary> /// The common code shared by all variants of SetValue /// </summary> // Takes metadata from caller because most of them have already retrieved it // for their own purposes, avoiding the duplicate GetMetadata call. private void SetValueCommon( DependencyProperty dp, object value, PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, OperationType operationType, bool isInternal) { if (IsSealed) { throw new InvalidOperationException(SR.Get(SRID.SetOnReadOnlyObjectNotAllowed, this)); } Expression newExpr = null; DependencySource[] newSources = null; EntryIndex entryIndex = LookupEntry(dp.GlobalIndex); // Treat Unset as a Clear if( value == DependencyProperty.UnsetValue ) { // Parameters should have already been validated, so we call // into the private method to avoid validating again. ClearValueCommon(entryIndex, dp, metadata); return; } // Validate the "value" against the DP. bool isDeferredReference = false; bool newValueHasExpressionMarker = (value == ExpressionInAlternativeStore); // First try to validate the value; only after this validation fails should we // do the more expensive checks (type checks) for the less common scenarios if (!newValueHasExpressionMarker) { bool isValidValue = isInternal ? dp.IsValidValueInternal(value) : dp.IsValidValue(value); // for properties of type "object", we have to always check for expression & deferredreference if (!isValidValue || dp.IsObjectType) { // 2nd most common is expression newExpr = value as Expression; if (newExpr != null) { // For Expressions, perform additional validation // Make sure Expression is "attachable" if (!newExpr.Attachable) { throw new ArgumentException(SR.Get(SRID.SharingNonSharableExpression)); } // Check dispatchers of all Sources // CALLBACK newSources = newExpr.GetSources(); ValidateSources(this, newSources, newExpr); } else { // and least common is DeferredReference isDeferredReference = (value is DeferredReference); if (!isDeferredReference) { if (!isValidValue) { // it's not a valid value & it's not an expression, so throw throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, value, dp.Name)); } } } } } // Get old value EffectiveValueEntry oldEntry; if (operationType == OperationType.ChangeMutableDefaultValue) { oldEntry = new EffectiveValueEntry(dp, BaseValueSourceInternal.Default); oldEntry.Value = value; } else { oldEntry = GetValueEntry(entryIndex, dp, metadata, RequestFlags.RawEntry); } // if there's an expression in some other store, fetch it now Expression currentExpr = (oldEntry.HasExpressionMarker) ? _getExpressionCore(this, dp, metadata) : (oldEntry.IsExpression) ? (oldEntry.LocalValue as Expression) : null; // Allow expression to store value if new value is // not an Expression, if applicable bool handled = false; if ((currentExpr != null) && (newExpr == null)) { // Resolve deferred references because we haven't modified // the expression code to work with DeferredReference yet. if (isDeferredReference) { value = ((DeferredReference) value).GetValue(BaseValueSourceInternal.Local); } // CALLBACK handled = currentExpr.SetValue(this, dp, value); entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex); } // Create the new effective value entry EffectiveValueEntry newEntry; if (handled) { // If expression handled set, then done if (entryIndex.Found) { newEntry = _effectiveValues[entryIndex.Index]; } else { // the expression.SetValue resulted in this value being removed from the table; // use the default value. newEntry = EffectiveValueEntry.CreateDefaultValueEntry(dp, metadata.GetDefaultValue(this, dp)); } coerceWithCurrentValue = false; // expression already handled the control-value } else { // allow a control-value to coerce an expression value, when the // expression didn't handle the value if (coerceWithCurrentValue && currentExpr != null) { currentExpr = null; } newEntry = new EffectiveValueEntry(dp, BaseValueSourceInternal.Local); // detach the old expression, if applicable if (currentExpr != null) { // CALLBACK DependencySource[] currentSources = currentExpr.GetSources(); UpdateSourceDependentLists(this, dp, currentSources, currentExpr, false); // Remove // CALLBACK currentExpr.OnDetach(this, dp); currentExpr.MarkDetached(); entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex); } // attach the new expression, if applicable if (newExpr == null) { // simple local value set newEntry.HasExpressionMarker = newValueHasExpressionMarker; newEntry.Value = value; } else { Debug.Assert(!coerceWithCurrentValue, "Expression values not supported in SetCurrentValue"); // First put the expression in the effectivevalueentry table for this object; // this allows the expression to update the value accordingly in OnAttach SetEffectiveValue(entryIndex, dp, dp.GlobalIndex, metadata, newExpr, BaseValueSourceInternal.Local); // Before the expression is attached it has default value object defaultValue = metadata.GetDefaultValue(this, dp); entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex); SetExpressionValue(entryIndex, defaultValue, newExpr); UpdateSourceDependentLists(this, dp, newSources, newExpr, true); // Add newExpr.MarkAttached(); // CALLBACK newExpr.OnAttach(this, dp); // the attach may have added entries in the effective value table ... // so, update the entryIndex accordingly. entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex); newEntry = EvaluateExpression( entryIndex, dp, newExpr, metadata, oldEntry, _effectiveValues[entryIndex.Index]); entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex); } } UpdateEffectiveValue( entryIndex, dp, metadata, oldEntry, ref newEntry, coerceWithDeferredReference, coerceWithCurrentValue, operationType); }
public static DependencyPropertyKey RegisterAttachedReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata metadata = null, ValidateValueCallback validateValueCallback = null) { DependencyPropertyHashKey key = new DependencyPropertyHashKey(ownerType, name); DependencyPropertyKey readOnlyKey = new DependencyPropertyKey(Register(key, propertyType, metadata, validateValueCallback, true, true)); registeredReadOnlyPropertiesKey.Add(key, readOnlyKey); return(readOnlyKey); }
[FriendAccessAllowed] // Built into Base, also used by Core and Framework. internal void SetEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, int targetIndex, PropertyMetadata metadata, object value, BaseValueSourceInternal valueSource) { Debug.Assert(value != DependencyProperty.UnsetValue, "Value to be set cannot be UnsetValue"); Debug.Assert(valueSource != BaseValueSourceInternal.Unknown, "ValueSource cannot be Unknown"); // For thread-safety, sealed DOs can't modify _effectiveValues. Debug.Assert(!DO_Sealed, "A Sealed DO cannot be modified"); if (metadata != null && metadata.IsInherited && valueSource != BaseValueSourceInternal.Inherited && !IsSelfInheritanceParent) { SetIsSelfInheritanceParent(); entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex); } EffectiveValueEntry entry; if (entryIndex.Found) { entry = _effectiveValues[entryIndex.Index]; } else { entry = new EffectiveValueEntry(); entry.PropertyIndex = targetIndex; InsertEntry(entry, entryIndex.Index); if (metadata != null && metadata.IsInherited) { InheritableEffectiveValuesCount++; } } bool hasExpressionMarker = (value == ExpressionInAlternativeStore); if (!hasExpressionMarker && entry.HasExpressionMarker && (valueSource == BaseValueSourceInternal.ThemeStyle || valueSource == BaseValueSourceInternal.ThemeStyleTrigger || valueSource == BaseValueSourceInternal.Style || valueSource == BaseValueSourceInternal.TemplateTrigger || valueSource == BaseValueSourceInternal.StyleTrigger || valueSource == BaseValueSourceInternal.ParentTemplate || valueSource == BaseValueSourceInternal.ParentTemplateTrigger)) { entry.BaseValueSourceInternal = valueSource; entry.SetExpressionValue(value, ExpressionInAlternativeStore); entry.ResetAnimatedValue(); entry.ResetCoercedValue(); } else if (entry.IsExpression && entry.ModifiedValue.ExpressionValue == Expression.NoValue) { // we now have a value for an expression that is "hiding" - save it // as the expression value entry.SetExpressionValue(value, entry.ModifiedValue.BaseValue); } else { Debug.Assert(entry.BaseValueSourceInternal != BaseValueSourceInternal.Local || valueSource == BaseValueSourceInternal.Local, "No one but another local value can stomp over an existing local value. The only way is to clear the entry"); entry.BaseValueSourceInternal = valueSource; entry.ResetValue(value, hasExpressionMarker); } Debug.Assert(dp == null || (dp.GlobalIndex == entry.PropertyIndex), "EffectiveValueEntry & DependencyProperty do not match"); _effectiveValues[entryIndex.Index] = entry; }
/// <summary> /// Simple registration, metadata, validation, and a read-only property /// key. Calling this version restricts the property such that it can /// only be set via the corresponding overload of DependencyObject.SetValue. /// </summary> public static DependencyPropertyKey RegisterAttachedReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback) { RegisterParameterValidation(name, propertyType, ownerType); // Establish default metadata for all types, if none is provided if (defaultMetadata == null) { defaultMetadata = AutoGeneratePropertyMetadata(propertyType, validateValueCallback, name, ownerType); } // We create a DependencyPropertyKey at this point with a null property // and set that in the _readOnlyKey field. This is so the property is // marked as requiring a key immediately. If something fails in the // initialization path, the property is still marked as needing a key. // This is better than the alternative of creating and setting the key // later, because if that code fails the read-only property would not // be marked read-only. The intent of this mildly convoluted code // is so we fail securely. DependencyPropertyKey authorizedKey = new DependencyPropertyKey(null); DependencyProperty property = RegisterCommon(name, propertyType, ownerType, defaultMetadata, validateValueCallback); property._readOnlyKey = authorizedKey; authorizedKey.SetDependencyProperty(property); return(authorizedKey); }
/// <summary> /// Simple registration, metadata, validation, and a read-only property /// key. Calling this version restricts the property such that it can /// only be set via the corresponding overload of DependencyObject.SetValue. /// </summary> public static DependencyPropertyKey RegisterAttachedReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata) { return(RegisterAttachedReadOnly(name, propertyType, ownerType, defaultMetadata, null)); }
/// <summary> /// Register an attached Dependency Property /// </summary> /// <param name="name">Name of property</param> /// <param name="propertyType">Type of the property</param> /// <param name="ownerType">Type that is registering the property</param> /// <param name="defaultMetadata">Metadata to use if current type doesn't specify type-specific metadata</param> /// <param name="validateValueCallback">Provides additional value validation outside automatic type validation</param> /// <returns>Dependency Property</returns> public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback) { RegisterParameterValidation(name, propertyType, ownerType); return(RegisterCommon(name, propertyType, ownerType, defaultMetadata, validateValueCallback)); }
/// <summary> /// Register an attached Dependency Property /// </summary> /// <param name="name">Name of property</param> /// <param name="propertyType">Type of the property</param> /// <param name="ownerType">Type that is registering the property</param> /// <param name="defaultMetadata">Metadata to use if current type doesn't specify type-specific metadata</param> /// <returns>Dependency Property</returns> public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata) { // Forwarding return(RegisterAttached(name, propertyType, ownerType, defaultMetadata, null)); }
private static DependencyProperty RegisterCommon(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback) { FromNameKey key = new FromNameKey(name, ownerType); lock (Synchronized) { if (PropertyFromName.Contains(key)) { throw new ArgumentException(SR.Get(SRID.PropertyAlreadyRegistered, name, ownerType.Name)); } } // Establish default metadata for all types, if none is provided if (defaultMetadata == null) { defaultMetadata = AutoGeneratePropertyMetadata(propertyType, validateValueCallback, name, ownerType); } else // Metadata object is provided. { // If the defaultValue wasn't specified auto generate one if (!defaultMetadata.DefaultValueWasSet()) { defaultMetadata.DefaultValue = AutoGenerateDefaultValue(propertyType); } ValidateMetadataDefaultValue(defaultMetadata, propertyType, name, validateValueCallback); } // Create property DependencyProperty dp = new DependencyProperty(name, propertyType, ownerType, defaultMetadata, validateValueCallback); // Seal (null means being used for default metadata, calls OnApply) defaultMetadata.Seal(dp, null); if (defaultMetadata.IsInherited) { dp._packedData |= Flags.IsPotentiallyInherited; } if (defaultMetadata.UsingDefaultValueFactory) { dp._packedData |= Flags.IsPotentiallyUsingDefaultValueFactory; } // Map owner type to this property // Build key lock (Synchronized) { PropertyFromName[key] = dp; } if (TraceDependencyProperty.IsEnabled) { TraceDependencyProperty.TraceActivityItem( TraceDependencyProperty.Register, dp, dp.OwnerType); } return(dp); }
/// <summary> /// Register a Dependency Property /// </summary> /// <param name="name">Name of property</param> /// <param name="propertyType">Type of the property</param> /// <param name="ownerType">Type that is registering the property</param> /// <param name="typeMetadata">Metadata to use if current type doesn't specify type-specific metadata</param> /// <returns>Dependency Property</returns> public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata) { // Forwarding return(Register(name, propertyType, ownerType, typeMetadata, null)); }
/// <summary> /// Register a Dependency Property /// </summary> /// <param name="name">Name of property</param> /// <param name="propertyType">Type of the property</param> /// <param name="ownerType">Type that is registering the property</param> /// <param name="typeMetadata">Metadata to use if current type doesn't specify type-specific metadata</param> /// <param name="validateValueCallback">Provides additional value validation outside automatic type validation</param> /// <returns>Dependency Property</returns> public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback) { RegisterParameterValidation(name, propertyType, ownerType); // Register an attached property PropertyMetadata defaultMetadata = null; if (typeMetadata != null && typeMetadata.DefaultValueWasSet()) { defaultMetadata = new PropertyMetadata(typeMetadata.DefaultValue); } DependencyProperty property = RegisterCommon(name, propertyType, ownerType, defaultMetadata, validateValueCallback); if (typeMetadata != null) { // Apply type-specific metadata to owner type only property.OverrideMetadata(ownerType, typeMetadata); } return(property); }
internal DeferredMutableDefaultReference(PropertyMetadata metadata, DependencyObject d, DependencyProperty dp) { _sourceObject = d; _sourceProperty = dp; _sourceMetadata = metadata; }
private static DependencyProperty Register(DependencyPropertyHashKey key, Type propertyType, PropertyMetadata metadata, ValidateValueCallback validateValueCallback, bool isAttached, bool isReadOnly) { if (metadata == null) { metadata = new PropertyMetadata(); } if (metadata.DefaultValue == null && propertyType.GetIsValueType()) { metadata.DefaultValue = Activator.CreateInstance(propertyType); } if (metadata.DefaultValue != null && !propertyType.IsInstanceOfType(metadata.DefaultValue)) { metadata.DefaultValue = ConvertDefaultValue(key, metadata.DefaultValue, propertyType); } DependencyProperty property = new DependencyProperty(key, propertyType, metadata, validateValueCallback, isAttached, isReadOnly); if (!property.IsValidValue(metadata.DefaultValue)) { throw new Granular.Exception("Default value validation of dependency property \"{0}.{1}\" failed", key.Owner.Name, key.Name); } AddRegisteredProperty(key, property); return(property); }
/// <summary> /// Merge set source state into this /// </summary> /// <remarks> /// Used when overriding metadata /// </remarks> /// <param name="baseMetadata">Base metadata to merge</param> /// <param name="dp">DependencyProperty that this metadata is being applied to</param> protected override void Merge(PropertyMetadata baseMetadata, DependencyProperty dp) { // Does parameter validation base.Merge(baseMetadata, dp); // Source type is guaranteed to be the same type or base type FrameworkPropertyMetadata fbaseMetadata = baseMetadata as FrameworkPropertyMetadata; if (fbaseMetadata != null) { // Merge source metadata into this // Modify metadata merge state fields directly (not through accessors // so that "modified" bits remain intact // Merge state // Defaults to false, derived classes can only enable WriteFlag(MetadataFlags.FW_AffectsMeasureID, ReadFlag(MetadataFlags.FW_AffectsMeasureID) | fbaseMetadata.AffectsMeasure); WriteFlag(MetadataFlags.FW_AffectsArrangeID, ReadFlag(MetadataFlags.FW_AffectsArrangeID) | fbaseMetadata.AffectsArrange); WriteFlag(MetadataFlags.FW_AffectsParentMeasureID, ReadFlag(MetadataFlags.FW_AffectsParentMeasureID) | fbaseMetadata.AffectsParentMeasure); WriteFlag(MetadataFlags.FW_AffectsParentArrangeID, ReadFlag(MetadataFlags.FW_AffectsParentArrangeID) | fbaseMetadata.AffectsParentArrange); WriteFlag(MetadataFlags.FW_AffectsRenderID, ReadFlag(MetadataFlags.FW_AffectsRenderID) | fbaseMetadata.AffectsRender); WriteFlag(MetadataFlags.FW_BindsTwoWayByDefaultID, ReadFlag(MetadataFlags.FW_BindsTwoWayByDefaultID) | fbaseMetadata.BindsTwoWayByDefault); WriteFlag(MetadataFlags.FW_IsNotDataBindableID, ReadFlag(MetadataFlags.FW_IsNotDataBindableID) | fbaseMetadata.IsNotDataBindable); // Override state if (!IsModified(MetadataFlags.FW_SubPropertiesDoNotAffectRenderModifiedID)) { WriteFlag(MetadataFlags.FW_SubPropertiesDoNotAffectRenderID, fbaseMetadata.SubPropertiesDoNotAffectRender); } if (!IsModified(MetadataFlags.FW_InheritsModifiedID)) { IsInherited = fbaseMetadata.Inherits; } if (!IsModified(MetadataFlags.FW_OverridesInheritanceBehaviorModifiedID)) { WriteFlag(MetadataFlags.FW_OverridesInheritanceBehaviorID, fbaseMetadata.OverridesInheritanceBehavior); } if (!IsModified(MetadataFlags.FW_ShouldBeJournaledModifiedID)) { WriteFlag(MetadataFlags.FW_ShouldBeJournaledID, fbaseMetadata.Journal); } if (!IsModified(MetadataFlags.FW_DefaultUpdateSourceTriggerModifiedID)) { // FW_DefaultUpdateSourceTriggerEnumBit1 = 0x40000000, // FW_DefaultUpdateSourceTriggerEnumBit2 = 0x80000000, _flags = (MetadataFlags)(((uint)_flags & 0x3FFFFFFF) | ((uint) fbaseMetadata.DefaultUpdateSourceTrigger) << 30); } } }
private DependencyProperty(DependencyPropertyHashKey hashKey, Type propertyType, PropertyMetadata metadata, ValidateValueCallback validateValueCallback, bool isAttached, bool isReadOnly) { this.hashKey = hashKey; this.Name = hashKey.Name; this.OwnerType = hashKey.Owner; this.PropertyType = propertyType; this.ValidateValueCallback = validateValueCallback; this.IsReadOnly = isReadOnly; this.Inherits = metadata.Inherits; this.StringKey = hashKey.StringKey; this.hashCode = hashKey.GetHashCode(); this.ownerMetadata = metadata; this.IsAttached = isAttached; typeMetadata = new ConvertedStringDictionary <Type, PropertyMetadata>(type => type.FullName); typeMetadata.Add(OwnerType, ownerMetadata); typeMetadataCache = CacheDictionary <Type, PropertyMetadata> .CreateUsingStringKeys(ResolveTypeMetadata, type => type.FullName); typeContainsCache = CacheDictionary <Type, bool> .CreateUsingStringKeys(ResolveTypeContains, type => type.FullName); }