Export (0) Print
Expand All

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)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public DrawingAttributes DefaultDrawingAttributes { get; set; }
<object>
  <object.DefaultDrawingAttributes>
    <DrawingAttributes .../>
  </object.DefaultDrawingAttributes>
</object>

Property Value

Type: System.Windows.Ink.DrawingAttributes
The default drawing attributes for the InkCanvas.

Identifier field

DefaultDrawingAttributesProperty

Metadata properties set to true

None

Setting this property will affect only new strokes that are made after this property is set. To apply new drawing attributes to already-created Stroke objects, access them individually using the Strokes property.

The following example demonstrates how to use two DrawingAttributes objects to simulate the experience of using a pen and a highlighter on the same InkCanvas. The example assumes that 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.

        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;

            }
        }

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

<Canvas.Resources>
  <!--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"/>
  </x:Array>

  <!--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}"/>
      </Border.Background>
    </Border>
  </DataTemplate>
</Canvas.Resources>


...


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

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, 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.

Show:
© 2014 Microsoft