PDA

View Full Version : InkCanvas problem



maur3r
January 4th, 2009, 06:41 PM
Hi,
I have a question concerning InkCanvas control. Perhaps someone could solve my problem. Namely I'm adding a child to this control and after that want to use eraser. Unfortunately it's impossible to modify the child element using eraser, however, it's possible to use ink for this purposes. Of course there's a workaround to use white ink instead of eraser but I am wondering if it is possible to it the “right way”.

Regards,
Martin

kirupa
January 5th, 2009, 02:35 AM
Hi Martin,
Are you trying to use the eraser to erase the contents of your child control? If so, that is unfortunately not possible. The eraser only erases ink strokes. Using a white stroke to simulate the eraser provides the closest visual effect of the image being erased.

Hope that helps :)

Cheers!
Kirupa :ub:

maur3r
January 5th, 2009, 06:26 PM
Hi Kirupa,
is it perhaps at least possible to change ink's stroke's shape? The size and color can be easily changed with the usage of DefaultDrawingAttributes class, however, I couldn't find any information how to change ink's stroke's shape.

maur3r
January 6th, 2009, 05:58 PM
Ok changing the shape of ink is trivial (StylusTip property), however, I couldn't find a way to define custom shape for my ink (other tam StylusTip.Rectangle or StylusTip.Elipse). Is that possible?

kirupa
January 7th, 2009, 01:07 AM
Hi maur3r,
Is this a WPF or Silverlight InkCanvas control?

Thanks,
Kirupa :)

maur3r
January 7th, 2009, 08:40 AM
Hi Kirupa,
this is WPF inkCanvas. What I'm trying to do is to solve my problem with eraser. When I switch ink's color to white it become invisible on the white background, therefore I would like to have some solid border around of it.
Another problem I have is with adding children to inkCanvas. When I already have some area covered with ink and add for instance rectangle, the control goes under the ink (attachement). I want to change it to have all controls and ink visible in the proper order (if the rectangle was added after the ink it should go above). Can you give me some tip how this could be done?

Regards,
Martin

kirupa
January 8th, 2009, 04:09 AM
Martin - I don't think it is possible to have a custom stylus tip. I have asked a few people, and I'll respond with more information if it is indeed possible to do that.

The InkCanvas is a bit unique and doesn't follow the traditional behavior of other layout panels as you have just found :)

One way of working around it is by placing your InkCanvas inside another Canvas. Now, if you add Rectangles and any other element to this parent Canvas, you will see that it gets added above your InkCanvas control.

Cheers!
Kirupa

maur3r
January 8th, 2009, 09:46 AM
Hi Kirupa,
thank you for your kind answers. The solution with two Canvas controls is indeed clever, however, it doesn't work for my purposes. I need to preserve order of children elements and ink. So if I create two Canvas controls, my shapes will be always above the ink, which isn't the behaviour I'm trying to achieve. I thought of converting children of InkCanvas to stroke. Is that possible?
Concerning the eraser, I thought of switching editingMode to none, defining custom Cursor and adding white child Rectangles (or any other shape) every time mouse is moved and LMB is down, however, I am wondering how CPU consuming is that. If I could, however, convert InkCanvas' children to stroke this wouldn't be a issue.

kirupa
January 11th, 2009, 06:36 AM
One way of doing this would be to programmatically insert a new incanvas control after you insert a shape. This way, you have your original ink canvas control with its strokes, you have your children elements, you may have another ink canvas control with shapes, etc.


The downside is that, if you are attempting to save all of that information, you not only have to remember the ink strokes, but you also have to remember the various ink canvas controls that are there.

Cheers!
Kirupa :)

maur3r
January 11th, 2009, 08:35 PM
Hi Kirupa,
thank you for your answer, however, I would prefer to somehow obtain stylus points that can be added to inkCanvas


Stroke s = new Stroke(pointsFromRectangle);
InkCanvas.Strokes.Add(s);

the problem is how to obtain StylusPointCollection (pointsFromRectangle) from a Shape.

robburke
February 9th, 2009, 04:10 PM
This MSDN post on custom ink may also be of help: http://msdn.microsoft.com/en-us/library/ms747347.aspx