DrawingAttributes.PropertyDataChanged Event

Definition

Occurs when property data is added or removed from the StrokeCollection.

C#
public event System.Windows.Ink.PropertyDataChangedEventHandler PropertyDataChanged;

Event Type

Examples

The following example is part of a custom stroke that can draw a three-dimensional effect. The stroke defines and stores a custom property called Shadowed, which belongs to DrawingAttributes. When the Shadowed property changes, the PropertyDataChanged event handler calls the OnInvalidated method, which causes the stroke to be redrawn.

C#
class ShadowedStroke : Stroke
{

    // Be sure to pass in the DrawingAttributes when you create the stroke to
    // subscribe to the PropertyDataChaned event.
    public ShadowedStroke(StylusPointCollection stylusPoints, DrawingAttributes drawingAttributes)
        : base(stylusPoints, drawingAttributes)
    {
        this.DrawingAttributes.PropertyDataChanged += new PropertyDataChangedEventHandler(DrawingAttributes_PropertyDataChanged);
    }

    Guid shadow = new Guid("12345678-9012-3456-7890-123456789012");

    public bool Shadowed
    {
        // Return the value of the custom property, shadow.
        // If there is no custom property, return false.
        get
        {
            if (!this.DrawingAttributes.ContainsPropertyData(shadow))
            {
                return false;
            }

            object propertyData = this.DrawingAttributes.GetPropertyData(shadow);

            if (propertyData is bool)
            {
                return (bool)propertyData;
            }
            else
            {
                return false;
            }
        }

        // Set the value of the custom property.
        set
        {
            this.DrawingAttributes.AddPropertyData(shadow, value);
        }
    }

    void DrawingAttributes_PropertyDataChanged(object sender, PropertyDataChangedEventArgs e)
    {
         this.OnInvalidated(new EventArgs());
    }

    protected override void DrawCore(System.Windows.Media.DrawingContext context, DrawingAttributes overrides)
    {
        // create a drop shadow
        //
        if (this.Shadowed)
        {
            Geometry pathGeometry = this.GetGeometry(overrides).Clone();
            pathGeometry.Transform = new TranslateTransform(5, 0);
            try
            {
                context.PushOpacity(0.5);
                context.DrawGeometry(Brushes.DarkGray, null, pathGeometry);
            }
            finally
            {
                context.Pop();
            }
        }
        base.DrawCore(context, overrides);
    }
}

Applies to

Produk Versi
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10