DrawingAttributes Class

DrawingAttributes Class

Specifies the appearance of a Stroke


Namespace:  System.Windows.Ink
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public class DrawingAttributes : INotifyPropertyChanged
This class is not typically used in XAML.

The DrawingAttributes type exposes the following members.

Public methodDrawingAttributesInitializes a new instance of the DrawingAttributes class.

Public propertyColorGets or sets the color of a Stroke.
Public propertyFitToCurveGets or sets a value that indicates whether Bezier smoothing is used to render the Stroke.
Public propertyHeightGets or sets the height of the stylus used to draw the Stroke.
Public propertyIgnorePressureGets or sets a value that indicates whether the thickness of a rendered Stroke changes according the amount of pressure applied.
Public propertyIsHighlighterGets or sets a value that indicates whether the Stroke looks like a highlighter.
Public propertyStylusTipGets or sets the shape of the stylus used to draw the Stroke.
Public propertyStylusTipTransformGets or sets the Matrix that specifies the transformation to perform on the stylus' tip.
Public propertyWidthGets or sets the width of the stylus used to draw the Stroke.

Public methodAddPropertyDataAdds a custom property to the DrawingAttributes object.
Public methodCloneCopies the DrawingAttributes object.
Public methodContainsPropertyDataReturns a value that indicates whether the specified property data identifier is in the DrawingAttributes object.
Public methodEqualsDetermines whether the specified DrawingAttributes object is equal to the current DrawingAttributes object. (Overrides Object.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Overrides Object.GetHashCode().)
Public methodGetPropertyDataGets the value of the custom property associated with the specified Guid.
Public methodGetPropertyDataIdsReturns the GUIDs of any custom properties associated with the StrokeCollection.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnAttributeChangedRaises the AttributeChanged event.
Protected methodOnPropertyChangedInfrastructure. Occurs when any DrawingAttributes property changes.
Protected methodOnPropertyDataChangedRaises the PropertyDataChanged event.
Public methodRemovePropertyDataRemoves the custom property associated with the specified Guid.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Public eventAttributeChangedOccurs when a property in the DrawingAttributes object changes.
Public eventPropertyDataChangedOccurs when property data is added or removed from the StrokeCollection.

Public operatorStatic memberEqualityDetermines whether the specified DrawingAttributes objects are equal.
Public operatorStatic memberInequalityDetermines whether the specified DrawingAttributes objects are not equal.

Public fieldStatic memberMaxHeightSpecifies the largest value allowed for the Height property.
Public fieldStatic memberMaxWidthSpecifies the largest value allowed for the Width property.
Public fieldStatic memberMinHeightSpecifies the smallest value allowed for the Height property.
Public fieldStatic memberMinWidthSpecifies the smallest value allowed for the Width property.

Explicit interface implemetationPrivate eventINotifyPropertyChanged.PropertyChangedInfrastructure. Occurs when the value of any DrawingAttributes property has changed.

Use the DrawingAttributes property to specify settings such as color, width, transparency, and the shape of the stylus tip for a Stroke.

Use the DefaultDrawingAttributes property to specify the drawing attributes for the strokes added to an InkCanvas. Only strokes that are added after the DefaultDrawingAttributes undergo change show the updated attributes. The appearance of the strokes that are already on the InkCanvas does not change.

For a list of initial property values for an instance of the DrawingAttributes class, see the DrawingAttributes constructor.

The following example demonstrates how to use two DrawingAttributes objects to simulate using a pen and a highlighter on the same InkCanvas. The example assumes the root element in the XAML file is a DockPanel called root. It also assumes that there is a Button called switchHighlighter and that the Click event is connected to the event handler defined in this example.

        InkCanvas inkCanvas1 = new InkCanvas();
        DrawingAttributes inkDA;
        DrawingAttributes highlighterDA;
        bool useHighlighter = false;

        // Add an InkCanvas to the window, and allow the user to 
        // switch between using a green pen and a purple highlighter 
        // on the InkCanvas.
        private void WindowLoaded(object sender, EventArgs e)
            inkCanvas1.Background = Brushes.DarkSlateBlue;
            inkCanvas1.DefaultDrawingAttributes.Color = Colors.SpringGreen;


            // Set up the DrawingAttributes for the pen.
            inkDA = new DrawingAttributes();
            inkDA.Color = Colors.SpringGreen;
            inkDA.Height = 5;
            inkDA.Width = 5;
            inkDA.FitToCurve = false;

            // Set up the DrawingAttributes for the highlighter.
            highlighterDA = new DrawingAttributes();
            highlighterDA.Color = Colors.Orchid;
            highlighterDA.IsHighlighter = true;
            highlighterDA.IgnorePressure = true;
            highlighterDA.StylusTip = StylusTip.Rectangle;
            highlighterDA.Height = 30;
            highlighterDA.Width = 10;

            inkCanvas1.DefaultDrawingAttributes = inkDA;

        // Create a button called switchHighlighter and use 
        // SwitchHighlighter_Click to handle the Click event.  
        // The useHighlighter variable is a boolean that indicates
        // whether the InkCanvas renders ink as a highlighter.

        // Switch between using the 'pen' DrawingAttributes and the 
        // 'highlighter' DrawingAttributes.
        void SwitchHighlighter_Click(Object sender, RoutedEventArgs e)
            useHighlighter = !useHighlighter;

            if (useHighlighter)
                switchHighlighter.Content = "Use Pen";
                inkCanvas1.DefaultDrawingAttributes = highlighterDA;
                switchHighlighter.Content = "Use Highlighter";
                inkCanvas1.DefaultDrawingAttributes = inkDA;


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

© 2016 Microsoft