This documentation is archived and is not being maintained.

InkCanvas.DefaultDrawingAttributes Property

Gets or sets the drawing attributes that are applied to new ink strokes made on the InkCanvas.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

Public Property DefaultDrawingAttributes As DrawingAttributes
Dim instance As InkCanvas
Dim value As DrawingAttributes

value = instance.DefaultDrawingAttributes

instance.DefaultDrawingAttributes = value
/** @property */
public DrawingAttributes get_DefaultDrawingAttributes ()

/** @property */
public void set_DefaultDrawingAttributes (DrawingAttributes value)

public function get DefaultDrawingAttributes () : DrawingAttributes

public function set DefaultDrawingAttributes (value : DrawingAttributes)

    <DrawingAttributes .../>

Property Value

The default drawing attributes for the InkCanvas.

Setting this property will affect only new strokes made after the property has been set. To apply drawing attribute changes to already-created Stroke objects, access them individually through the Strokes property.

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 markup language (XAML) file is a DockPanel called root. It also assumes that there is a Button called switchHilighter 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.

    ' 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 .
Sub SwitchHighlighter_Click(ByVal sender As [Object], ByVal e As RoutedEventArgs)

    useHighlighter = Not useHighlighter

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

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

End Sub 'SwitchHighlighter_Click

The following example demonstrates how to bind the DefaultDrawingAttributes property to a data source.

  <!--Define an array containing some DrawingAttributes.-->
  <x:Array x:Key="MyDrawingAttributes" x:Type="{x:Type DrawingAttributes}">
    <DrawingAttributes Color="Black" FitToCurve="true" Width="3" Height="3"/>
    <DrawingAttributes Color="Blue"  FitToCurve="false" Width="5" Height="5"/>
    <DrawingAttributes Color="Red"   FitToCurve="true" Width="7" Height="7"/>

  <!--Create a DataTemplate to display the DrawingAttributes shown above-->
  <DataTemplate DataType="{x:Type DrawingAttributes}" >
    <Border Width="80" Height="{Binding Path=Height}">
      <Border.Background >
        <SolidColorBrush Color="{Binding Path=Color}"/>


<!--Bind the InkCavas' DefaultDrawingAtributes to
    a Listbox, called lbDrawingAttributes.-->
<InkCanvas Name="inkCanvas1" Background="LightGreen" 
           Canvas.Top="400" Canvas.Left="0" 
           Height="400" Width="400"
                ElementName=lbDrawingAttributes, Path=SelectedItem}"

<!--Use the array, MyDrawingAttributes, to populate a ListBox-->
<ListBox Name="lbDrawingAttributes" 
         Canvas.Top="400" Canvas.Left="450" 
         Height="100" Width="100"
         ItemsSource="{StaticResource MyDrawingAttributes}" />

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0