Friday, July 22, 2005 12:16 PM
SamGeo
Editing with InkCanvas
Going a little deeper into InkCanvas…
InkCanvas not only collects and renders ink, but it also allows editing of that ink, as well as any elements hosted in the InkCanvas. I wanted to talk about two very important properties on InkCanvas that control editing: InkCanvas.EditingMode and InkCanvas.EditingModeInverted
Both properties are of type InkCanvasEditingMode:
public enum InkCanvasEditingMode
{
None = 0,
Ink,
GestureOnly,
InkAndGesture,
Select,
EraseByPoint,
EraseByStroke,
}
InkCanvas.EditingMode controls the editing mode that InkCanvas uses for the tip of the Stylus, InkCanvas.EditingModeInverted controls the editing mode for the back of the Stylus (the eraser). By default, EditingMode is set to Ink, and EditingModeInverted is set to EraseByStroke. While our COM \ WinForms InkOverlay and InkPicture had an EditingMode property, they did not have an EditingModeInverted property. A common question developers had was how to implement back of Stylus erase; we’ve added the EditingModeInverted property to InkCanvas to make this work out of the box.
These properties are settable in XAML, so you can change the defaults as you like:
<Grid xmlns=http://schemas.microsoft.com/winfx/avalon/2005>
<InkCanvas EditingMode=”InkAndGesture” EditingModeInverted=”EraseByStroke”/>
</Grid>
This is what each InkCanvasEditingMode value does:
-
Ink: Ink is collected for the Stylus or Mouse. Any time a Stroke is collected (a series of down, optional move and up of the Stylus or Mouse), the InkCanvas.StrokeCollected event will be raised and the Stroke will be added to the InkCanvas’s StrokeCollection (available from the InkCanvas.Strokes property)
-
GestureOnly: Ink is collected, but after each Stroke, it is passed to the gesture recognizer (mshwgst.dll) if present and the Gesture event is raised. The event args for the Gesture event describe the gesture recognition results. Once the event fires, the Stroke is removed from the InkCanvas.
That’s all for now. Next time… using InkCanvas.DefaultDrawingAttributes to control how new Strokes look when added to the InkCanvas.