Skip to main content
.NET Framework Class Library
DrawingAttributes Class

Specifies the appearance of a Stroke

Inheritance Hierarchy
SystemObject
  System.Windows.InkDrawingAttributes

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
Syntax
Public Class DrawingAttributes _
	Implements [%$TOPIC/ms616713_en-us_VS_110_3_0_0_0_0%]
public class DrawingAttributes : [%$TOPIC/ms616713_en-us_VS_110_3_0_1_0_0%]
public ref class DrawingAttributes : [%$TOPIC/ms616713_en-us_VS_110_3_0_2_0_0%]
type DrawingAttributes =  
    class 
        interface [%$TOPIC/ms616713_en-us_VS_110_3_0_3_0_0%] 
    end

This class is not typically used in XAML.

The DrawingAttributes type exposes the following members.

Constructors
  NameDescription
Public method DrawingAttributesInitializes a new instance of the DrawingAttributes class.
Top
Properties
  NameDescription
Public property ColorGets or sets the color of a Stroke.
Public property FitToCurveGets or sets a value that indicates whether Bezier smoothing is used to render the Stroke.
Public property HeightGets or sets the height of the stylus used to draw the Stroke.
Public property IgnorePressureGets or sets a value that indicates whether the thickness of a rendered Stroke changes according the amount of pressure applied.
Public property IsHighlighterGets or sets a value that indicates whether the Stroke looks like a highlighter.
Public property StylusTipGets or sets the shape of the stylus used to draw the Stroke.
Public property StylusTipTransformGets or sets the Matrix that specifies the transformation to perform on the stylus' tip.
Public property WidthGets or sets the width of the stylus used to draw the Stroke.
Top
Methods
  NameDescription
Public method AddPropertyDataAdds a custom property to the DrawingAttributes object.
Public method CloneCopies the DrawingAttributes object.
Public method ContainsPropertyDataReturns a value that indicates whether the specified property data identifier is in the DrawingAttributes object.
Public method EqualsDetermines whether the specified DrawingAttributes object is equal to the current DrawingAttributes object. (Overrides ObjectEquals(Object).)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCodeServes as a hash function for a particular type. (Overrides ObjectGetHashCode.)
Public method GetPropertyDataGets the value of the custom property associated with the specified Guid.
Public method GetPropertyDataIdsReturns the GUIDs of any custom properties associated with the StrokeCollection.
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnAttributeChangedRaises the AttributeChanged event.
Protected method OnPropertyChangedInfrastructure. Occurs when any DrawingAttributes property changes.
Protected method OnPropertyDataChangedRaises the PropertyDataChanged event.
Public method RemovePropertyDataRemoves the custom property associated with the specified Guid.
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Events
  NameDescription
Public event AttributeChangedOccurs when a property in the DrawingAttributes object changes.
Public event PropertyDataChangedOccurs when property data is added or removed from the StrokeCollection.
Top
Operators
  NameDescription
Public operator Static member EqualityDetermines whether the specified DrawingAttributes objects are equal.
Public operator Static member InequalityDetermines whether the specified DrawingAttributes objects are not equal.
Top
Fields
  NameDescription
Public field Static member MaxHeightSpecifies the largest value allowed for the Height property.
Public field Static member MaxWidthSpecifies the largest value allowed for the Width property.
Public field Static member MinHeightSpecifies the smallest value allowed for the Height property.
Public field Static member MinWidthSpecifies the smallest value allowed for the Width property.
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private event INotifyPropertyChangedPropertyChangedInfrastructure. Occurs when the value of any DrawingAttributes property has changed.
Top
Remarks

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.

Examples

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.

    Private WithEvents inkCanvas1 As New InkCanvas()
    Private inkDA As DrawingAttributes
    Private highlighterDA As DrawingAttributes
    Private useHighlighter As Boolean = 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 Sub WindowLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)

        inkCanvas1.Background = Brushes.DarkSlateBlue
        inkCanvas1.DefaultDrawingAttributes.Color = Colors.SpringGreen

        ' Add the InkCanvas to the DockPanel, named root.
        root.Children.Add(inkCanvas1)

        ' Set up the DrawingAttributes for the pen.
        inkDA = New DrawingAttributes()
        With inkDA
            .Color = Colors.SpringGreen
            .Height = 5
            .Width = 5
            .FitToCurve = True
        End With

        ' Set up the DrawingAttributes for the highlighter.
        highlighterDA = New DrawingAttributes()
        With highlighterDA
            .Color = Colors.Orchid
            .IsHighlighter = True
            .IgnorePressure = True
            .StylusTip = StylusTip.Rectangle
            .Height = 30
            .Width = 10
        End With

        inkCanvas1.DefaultDrawingAttributes = inkDA

    End Sub 'WindowLoaded


    ' 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 when the user clicks on .
    Private Sub SwitchHighlighter_Click(ByVal sender As [Object], ByVal e As RoutedEventArgs)

        useHighlighter = Not useHighlighter

        If useHighlighter Then
            switchHighlighter.Content = "Use Pen"
            inkCanvas1.DefaultDrawingAttributes = highlighterDA
        Else

            switchHighlighter.Content = "Use Highlighter"
            inkCanvas1.DefaultDrawingAttributes = inkDA
        End If

    End Sub 'SwitchHighlighter_Click
        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;

            root.Children.Add(inkCanvas1);

            // 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;
            }
            else
            {
                switchHighlighter.Content = "Use Highlighter";
                inkCanvas1.DefaultDrawingAttributes = inkDA;

            }
        }
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

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