In fact, what we want to talk about today is a control-inkpresenter. This control is not very powerful and cannot be compared with inkcanvas in WPF. It is estimated that it is rarely used in actual development. However, let's take a look at it. After all, it's not difficult to use it.
This control has no technical content. Pay attention to the following points:
1. The width and height of inkpresenter must be specified explicitly, that is, automatic values and margin cannot be used. Otherwise, ink marks cannot be collected unless there are child elements in them;
2. To collect ink marks, set the clip attribute;
3. You can use the drawingattributes class to set the ink size and color.
This control cannot automatically collect ink marks like WPF does. That is to say, we can only write our own code.
[HTML]View plaincopyprint?
- <Grid>
- <Inkpresenter X: Name = "mypresenter"
- Horizontalalignment = "left"
- Verticalalignment = "TOP"
- Mouseleftbuttondown = "mypresenter_mouseleftbuttondown"
- Lostmousecapture = "mypresenter_lostmousecapture"
- Mousemove = "mypresenter_mousemove"
- Background = "Transparent"
- Opacity = "1" width = "480" Height = "750"/>
- </GRID>
[CSHARP]View plaincopyprint?
- Using system;
- Using system. Collections. Generic;
- Using system. LINQ;
- Using system. net;
- Using system. windows;
- Using system. Windows. controls;
- Using system. Windows. documents;
- Using system. Windows. input;
- Using system. Windows. Media;
- Using system. Windows. Media. animation;
- Using system. Windows. shapes;
- Using Microsoft. Phone. controls;
- // Introduce the following namespace.
- Using system. Windows. Ink;
- Namespace inkpresentsample
- {
- Public partial class mainpage: phoneapplicationpage
- {
- Stroke currentstroke = NULL;
- // Constructor
- Public mainpage ()
- {
- Initializecomponent ();
- // Set the clip to collect ink marks
- Rectanglegeometry Rg = new rectanglegeometry ();
- // The final height of the control should be used to make the range accurate.
- RG. rect = new rect (0, 0, mypresenter. actualwidth, mypresenter. actualheight );
- Mypresenter. Clip = RG;
- }
- Private void mypresenter_mouseleftbuttondown (Object sender, mousebuttoneventargs E)
- {
- // Capture the mouse and cursor when we click
- Mypresenter. capturemouse ();
- // Collect the points at which the current cursor is located
- Styluspointcollection SC = new styluspointcollection ();
- SC. Add (E. stylusdevice. getstyluspoints (mypresenter ));
- Currentstroke = new stroke (SC );
- // Set the stroke color and size
- Currentstroke. drawingattributes. Color = colors. Yellow;
- Currentstroke. drawingattributes. width = 8;
- Currentstroke. drawingattributes. Height = 8;
- // Add new strokes to the set
- Mypresenter. Strokes. Add (currentstroke );
- }
- Private void mypresenter_lostmousecapture (Object sender, mouseeventargs E)
- {
- // When the mouse is released, the reference of the stroke variable is also released.
- Currentstroke = NULL;
- }
- Private void mypresenter_mousemove (Object sender, mouseeventargs E)
- {
- If (currentstroke! = NULL)
- {
- // Each time you move the mouse, the corresponding points are collected.
- Currentstroke. styluspoints. Add (E. stylusdevice. getstyluspoints (mypresenter ));
- }
- }
- }
- }