Why should I use the InkCanvas in WPF?
Asked Answered
P

4

15

In my WPF application I have some drawing functionality. I have solved this using a Canvas and handling mouse gestures manually, and I also add the drawn Strokes (wrapped in InkPresenter) to this Canvas.

Using Blend I suddenly discover that there is something called InkCanvas. According to Blend this is a control that "Defines an area that receives and displays ink strokes.", so it sounds relevant to what I do. But everything seems to work fine using a plain Canvas..

So; how does the InkCanvas differ from the plain Canvas, and why should I choose to use this instead?

Protean answered 9/3, 2010 at 14:11 Comment(0)
P
14

They really are meant to serve two different purposes. Canvas is for layout. Specifically for more exact control over layout using absolute positioning. InkCanvas is, as you know, for capturing and displaying strokes.

What you are doing is just fine, but InkCanvas has some nice additional features like EditMode among others. It is meant to save you from writing a lot of the stuff you would have to do by hand using Canvas. Using Canvas is a roll your own kind of approach where InkCanvas is a use a pre-built in kind of approach.

Pigeontoed answered 9/3, 2010 at 14:27 Comment(1)
@Jeff Yates - Thanks! I must have typed server out of force of habit.Pigeontoed
K
8

An InkCanvas handles the mouse events for you to draw on the canvas. It also has this functionality:

  • Save/Load
  • Resize/Scale
  • Highlight behind text
  • Eraser mode

http://www.kirupa.com/blend_wpf/inkcanvas_pg1.htm

Kori answered 9/3, 2010 at 14:31 Comment(0)
C
4

When performance in concerned, InkCanvas with real mouse events is much faster than creating a stroke out of StylusPointCollection, I found that adding new points to a StylusPointCollection is an expensive operation.

Consol answered 4/9, 2011 at 13:5 Comment(0)
F
2

we can develop whiteboard application,paint application using InkCanvas WPF. EditMode gives us so many features like Gestures,drawing,,erasing,multi touch operations,select element drag drop options. insert elements like shapes,images,videos,stroke annotations we can save/load all strokes and elements. we can customise InkCanvas class.

Fichte answered 3/9, 2020 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.