Originally available only as part of the Tablet PC SDK, digital ink is now integrated into Microsoft's Windows Presentation Foundation. With the exception of handwriting recognition, Windows programmers can now leverage digital ink in their applications without additional SDKs or runtime libraries.
Enabling Ink
To enable the collection and display of ink input, developers need only include the InkCanvas element in their XAML document.
<Window x:Class="WindowsApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WindowsApplication1" Width="550" Height="400"> <Grid> <InkCanvas /> </Grid> </Window>
When the above code is compiled, a small black square replaces the mouse cursor when the user hovers over the application window. When the user left-clicks and drags the mouse in the content area, "ink" is invoked and the user is able to draw.
Like other tags in XAML, InkCanvas can be used in conjunction with other layout elements and controls. As such, it may be positioned or layered over other elements. The following example displays an image within an InkCanvas.
<Window x:Class="WindowsApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WindowsApplication1" Width="550" Height="400"> <Grid> <InkCanvas> <Image Source="http://www.google.com/intl/en/images/logo.gif" /> </InkCanvas> </Grid> </Window>
When compiled, the user is able to draw on the image because the graphic is a child of the InkCanvas element.
Using just a bit of C#, it is also possible to control a number of ink properties including stroke color and thickness. These properties are controlled using the DrawingAttributes class.
Using this class, you can either control the appearance of individual strokes using Stroke.DrawingAttributes or the default appearance of any new stroke collected by the InkCanvas using InkCanvas.DefaultDrawingAttributes.
Below is a list of properties supported by the DrawingAttributes class:
Name Description Color Gets or sets the color of a Stroke. FitToCurve Gets or sets a value that indicates whether Bezier smoothing is used to render the Stroke. Height Gets or sets the height of the stylus used to draw the Stroke. IgnorePressure Gets or sets a value that indicates whether the thickness of a rendered Stroke changes according the amount of pressure applied. IsHighlighter Gets or sets a value that indicates whether the Stroke looks like a highlighter. StylusTip Gets or sets the shape of the stylus used to draw the Stroke. StylusTipTransform Gets or sets the Matrix that specifies the transformation to perform on the stylus' tip.
Join the conversation! Your thoughts help the community grow.