/// <summary> /// Method called on derived classes whenever a change occurs in /// the PropertyData. /// </summary> /// <remarks>Derived classes should call this method (their base class) /// to ensure that event listeners are notified</remarks> protected virtual void OnPropertyDataChanged(PropertyDataChangedEventArgs e) { if (null == e) { throw new ArgumentNullException("e", SR.Get(SRID.EventArgIsNull)); } if (this.PropertyDataChanged != null) { this.PropertyDataChanged(this, e); } }
/// <summary> /// Method called whenever the Stroke's drawing attributes are changed. /// This method will trigger an event for any listeners interested in /// drawing attributes. /// </summary> /// <param name="sender">The Drawing Attributes object that was changed</param> /// <param name="e">More data about the change that occurred</param> private void DrawingAttributes_Changed(object sender, PropertyDataChangedEventArgs e) { // set Geometry flag to be dirty if the DA change will cause change in geometry if (DrawingAttributes.IsGeometricalDaGuid(e.PropertyGuid) == true) { _cachedGeometry = null; // Set the cached bounds to empty, which will force a re-calculation of the _cachedBounds upon next GetBounds call. _cachedBounds = Rect.Empty; } OnDrawingAttributesChanged(e); if (!_delayRaiseInvalidated) { //when Stroke.Transform(Matrix, bool) is called, we don't raise invalidated from //here, but rather from the Stroke.Transform method. OnInvalidated(EventArgs.Empty); } }
/// <summary> /// A help method which fires INotifyPropertyChanged.PropertyChanged event /// </summary> /// <param name="e"></param> private void PrivateNotifyPropertyChanged(PropertyDataChangedEventArgs e) { if (e.PropertyGuid == KnownIds.Color) { OnPropertyChanged("Color"); } else if (e.PropertyGuid == KnownIds.StylusTip) { OnPropertyChanged("StylusTip"); } else if (e.PropertyGuid == KnownIds.StylusTipTransform) { OnPropertyChanged("StylusTipTransform"); } else if (e.PropertyGuid == KnownIds.StylusHeight) { OnPropertyChanged("Height"); } else if (e.PropertyGuid == KnownIds.StylusWidth) { OnPropertyChanged("Width"); } else if (e.PropertyGuid == KnownIds.IsHighlighter) { OnPropertyChanged("IsHighlighter"); } else if (e.PropertyGuid == KnownIds.DrawingFlags) { DrawingFlags changedBits = (((DrawingFlags)e.PreviousValue) ^ ((DrawingFlags)e.NewValue)); // NOTICE-2006/01/20-WAYNEZEN, // If someone changes FitToCurve and IgnorePressure simultaneously via AddPropertyData/RemovePropertyData, // we will fire both OnPropertyChangeds in advance the order of the values. if ((changedBits & DrawingFlags.FitToCurve) != 0) { OnPropertyChanged("FitToCurve"); } if ((changedBits & DrawingFlags.IgnorePressure) != 0) { OnPropertyChanged("IgnorePressure"); } } }
/// <summary> /// Method called when a change occurs to any DrawingAttribute /// </summary> /// <param name="e">The change information for the DrawingAttribute that was modified</param> protected virtual void OnAttributeChanged(PropertyDataChangedEventArgs e) { if (null == e) { throw new ArgumentNullException("e", SR.Get(SRID.EventArgIsNull)); } try { PrivateNotifyPropertyChanged(e); } finally { if (this.AttributeChanged != null) { this.AttributeChanged(this, e); } } }
/// <summary> /// A handler for both AttributeChanged and PropertyDataChanged. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> internal void OnDrawingAttributesChanged(object sender, PropertyDataChangedEventArgs e) { DrawingAttributes value = (DrawingAttributes)sender; // The current instance will be promoted to the local value other than the default value. // Then we could just remove our handlers to stop tracking. value.AttributeChanged -= new PropertyDataChangedEventHandler(OnDrawingAttributesChanged); value.PropertyDataChanged -= new PropertyDataChangedEventHandler(OnDrawingAttributesChanged); // NTRAID#WINDOWS-1334059-2005/10/17-waynezen, // We only promote the value when there is no local value set yet. if (_owner.ReadLocalValue(InkCanvas.DefaultDrawingAttributesProperty) == DependencyProperty.UnsetValue) { // Promote the instance to the local value. _owner.SetValue(InkCanvas.DefaultDrawingAttributesProperty, value); } // Remove this value from the DefaultValue cache so we stop // handing it out as the default value now that it has changed. PropertyMetadata metadata = InkCanvas.DefaultDrawingAttributesProperty.GetMetadata(_owner.DependencyObjectType); metadata.ClearCachedDefaultValue(_owner, InkCanvas.DefaultDrawingAttributesProperty); }
protected virtual new void OnPropertyDataChanged(PropertyDataChangedEventArgs e) { }
/// <summary> /// Event handler for stroke's drawing attributes changes. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnStrokeDrawingAttributesChanged(object sender, PropertyDataChangedEventArgs args) { // Only enforce rehittesting of the whole stroke when the DrawingAttribute change may affect hittesting if(DrawingAttributes.IsGeometricalDaGuid(args.PropertyGuid)) { Invalidate(); } }
/// <summary> /// A help method which fires INotifyPropertyChanged.PropertyChanged event /// </summary> /// <param name="e"></param> private void PrivateNotifyPropertyChanged(PropertyDataChangedEventArgs e) { if ( e.PropertyGuid == KnownIds.Color) { OnPropertyChanged("Color"); } else if ( e.PropertyGuid == KnownIds.StylusTip) { OnPropertyChanged("StylusTip"); } else if ( e.PropertyGuid == KnownIds.StylusTipTransform) { OnPropertyChanged("StylusTipTransform"); } else if ( e.PropertyGuid == KnownIds.StylusHeight) { OnPropertyChanged("Height"); } else if ( e.PropertyGuid == KnownIds.StylusWidth) { OnPropertyChanged("Width"); } else if ( e.PropertyGuid == KnownIds.IsHighlighter) { OnPropertyChanged("IsHighlighter"); } else if ( e.PropertyGuid == KnownIds.DrawingFlags ) { DrawingFlags changedBits = ( ( (DrawingFlags)e.PreviousValue ) ^ ( (DrawingFlags)e.NewValue ) ); // NOTICE-2006/01/20-WAYNEZEN, // If someone changes FitToCurve and IgnorePressure simultaneously via AddPropertyData/RemovePropertyData, // we will fire both OnPropertyChangeds in advance the order of the values. if ( (changedBits & DrawingFlags.FitToCurve) != 0 ) { OnPropertyChanged("FitToCurve"); } if ( (changedBits & DrawingFlags.IgnorePressure) != 0 ) { OnPropertyChanged("IgnorePressure"); } } }
/// <summary> /// Whenever the base class fires the generic ExtendedPropertiesChanged /// event, we need to fire the DrawingAttributesChanged event also. /// </summary> /// <param name="sender">Should be 'this' object</param> /// <param name="args">The custom attributes that changed</param> private void ExtendedPropertiesChanged_EventForwarder(object sender, ExtendedPropertiesChangedEventArgs args) { System.Diagnostics.Debug.Assert(sender != null); System.Diagnostics.Debug.Assert(args != null); //see if the EP that changed is a drawingattribute if (args.NewProperty == null) { //a property was removed, see if it is a drawing attribute property object defaultValueIfDrawingAttribute = DrawingAttributes.GetDefaultDrawingAttributeValue(args.OldProperty.Id); if (defaultValueIfDrawingAttribute != null) { ExtendedProperty newProperty = new ExtendedProperty( args.OldProperty.Id, defaultValueIfDrawingAttribute); //this is a da guid PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs( args.OldProperty.Id, newProperty.Value, //the property args.OldProperty.Value);//previous value this.OnAttributeChanged(dargs); } else { PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs( args.OldProperty.Id, null, //the property args.OldProperty.Value);//previous value this.OnPropertyDataChanged(dargs); } } else if (args.OldProperty == null) { //a property was added, see if it is a drawing attribute property object defaultValueIfDrawingAttribute = DrawingAttributes.GetDefaultDrawingAttributeValue(args.NewProperty.Id); if (defaultValueIfDrawingAttribute != null) { if (!defaultValueIfDrawingAttribute.Equals(args.NewProperty.Value)) { //this is a da guid PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs( args.NewProperty.Id, args.NewProperty.Value, //the property defaultValueIfDrawingAttribute); //previous value this.OnAttributeChanged(dargs); } } else { PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs(args.NewProperty.Id, args.NewProperty.Value, //the property null); //previous value this.OnPropertyDataChanged(dargs); } } else { //something was modified, see if it is a drawing attribute property object defaultValueIfDrawingAttribute = DrawingAttributes.GetDefaultDrawingAttributeValue(args.NewProperty.Id); if (defaultValueIfDrawingAttribute != null) { // // we only raise DA changed when the value actually changes // if (!args.NewProperty.Value.Equals(args.OldProperty.Value)) { //this is a da guid PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs( args.NewProperty.Id, args.NewProperty.Value, //the da args.OldProperty.Value);//old value this.OnAttributeChanged(dargs); } } else { if (!args.NewProperty.Value.Equals(args.OldProperty.Value)) { PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs( args.NewProperty.Id, args.NewProperty.Value, args.OldProperty.Value);//old value this.OnPropertyDataChanged(dargs); } } } }
/// <summary> /// Method called when a change occurs to any PropertyData /// </summary> /// <param name="e">The change information for the PropertyData that was modified</param> protected virtual void OnPropertyDataChanged(PropertyDataChangedEventArgs e) { if (null == e) { throw new ArgumentNullException("e", SR.Get(SRID.EventArgIsNull)); } if (this.PropertyDataChanged != null) { this.PropertyDataChanged(this, e); } }
/// <summary> /// Method called when a change occurs to any DrawingAttribute /// </summary> /// <param name="e">The change information for the DrawingAttribute that was modified</param> protected virtual void OnAttributeChanged(PropertyDataChangedEventArgs e) { if (null == e) { throw new ArgumentNullException("e", SR.Get(SRID.EventArgIsNull)); } try { PrivateNotifyPropertyChanged(e); } finally { if ( this.AttributeChanged != null ) { this.AttributeChanged(this, e); } } }
protected virtual new void OnDrawingAttributesChanged(PropertyDataChangedEventArgs e) { }
/// <summary> /// Whenever the base class fires the generic ExtendedPropertiesChanged /// event, we need to fire the DrawingAttributesChanged event also. /// </summary> /// <param name="sender">Should be 'this' object</param> /// <param name="args">The custom attributes that changed</param> private void ExtendedPropertiesChanged_EventForwarder(object sender, ExtendedPropertiesChangedEventArgs args) { System.Diagnostics.Debug.Assert(sender != null); System.Diagnostics.Debug.Assert(args != null); //see if the EP that changed is a drawingattribute if (args.NewProperty == null) { //a property was removed, see if it is a drawing attribute property object defaultValueIfDrawingAttribute = DrawingAttributes.GetDefaultDrawingAttributeValue(args.OldProperty.Id); if (defaultValueIfDrawingAttribute != null) { ExtendedProperty newProperty = new ExtendedProperty(args.OldProperty.Id, defaultValueIfDrawingAttribute); //this is a da guid PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs(args.OldProperty.Id, newProperty.Value, //the property args.OldProperty.Value); //previous value this.OnAttributeChanged(dargs); } else { PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs(args.OldProperty.Id, null, //the property args.OldProperty.Value); //previous value this.OnPropertyDataChanged(dargs); } } else if (args.OldProperty == null) { //a property was added, see if it is a drawing attribute property object defaultValueIfDrawingAttribute = DrawingAttributes.GetDefaultDrawingAttributeValue(args.NewProperty.Id); if (defaultValueIfDrawingAttribute != null) { if (!defaultValueIfDrawingAttribute.Equals(args.NewProperty.Value)) { //this is a da guid PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs(args.NewProperty.Id, args.NewProperty.Value, //the property defaultValueIfDrawingAttribute); //previous value this.OnAttributeChanged(dargs); } } else { PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs(args.NewProperty.Id, args.NewProperty.Value, //the property null); //previous value this.OnPropertyDataChanged(dargs); } } else { //something was modified, see if it is a drawing attribute property object defaultValueIfDrawingAttribute = DrawingAttributes.GetDefaultDrawingAttributeValue(args.NewProperty.Id); if (defaultValueIfDrawingAttribute != null) { // // we only raise DA changed when the value actually changes // if (!args.NewProperty.Value.Equals(args.OldProperty.Value)) { //this is a da guid PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs(args.NewProperty.Id, args.NewProperty.Value, //the da args.OldProperty.Value); //old value this.OnAttributeChanged(dargs); } } else { if (!args.NewProperty.Value.Equals(args.OldProperty.Value)) { PropertyDataChangedEventArgs dargs = new PropertyDataChangedEventArgs(args.NewProperty.Id, args.NewProperty.Value, args.OldProperty.Value); //old value this.OnPropertyDataChanged(dargs); } } } }