What we're going to talk about today is a control--inkpresenter, a control that's not very powerful, and it's not likely to be used in real-world development compared to InkCanvas in WPF, but let's get to know it, after all, it's not hard to use.
There is no technical content to use the control, just take note of the following points:
1, must explicitly specify the width and height of the InkPresenter, that is, cannot use automatic values and margin, or cannot collect ink, unless there are child elements;
2, to collect ink, to set the clip properties;
3. You can use the DrawingAttributes class to set the size and color of the ink.
The control does not automatically implement the ability to collect ink like WPF, which means that we can only write our own code.
- <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= "/>"
- </Grid>
- 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;
- The following namespaces are introduced.
- Using System.Windows.Ink;
- Namespace Inkpresentsample
- {
- public partial class Mainpage:phoneapplicationpage
- {
- Stroke currentstroke = null;
- constructor function
- Public MainPage ()
- {
- InitializeComponent ();
- Set up a clip to collect ink
- RectangleGeometry RG = new RectangleGeometry ();
- To make the scope accurate, the final rendering height of the control should be used.
- Rg. rect = new Rect (0, 0, mypresenter.actualwidth, mypresenter.actualheight);
- Mypresenter.clip = RG;
- }
- private void Mypresenter_mouseleftbuttondown (object sender, MouseButtonEventArgs e)
- {
- When we click, we catch the mouse cursor
- Mypresenter.capturemouse ();
- Collects the point at which the current cursor is located
- StylusPointCollection sc = new StylusPointCollection ();
- Sc. ADD (E.stylusdevice.getstyluspoints (mypresenter));
- Currentstroke = new Stroke (SC);
- Set the stroke's color, size
- CurrentStroke.DrawingAttributes.Color = Colors.yellow;
- CurrentStroke.DrawingAttributes.Width = 8;
- CurrentStroke.DrawingAttributes.Height = 8;
- Add a new stroke to the collection
- MYPRESENTER.STROKES.ADD (Currentstroke);
- }
- private void Mypresenter_lostmousecapture (object sender, MouseEventArgs e)
- {
- When you release the mouse, the reference to the stroke variable is also released
- Currentstroke = null;
- }
- private void Mypresenter_mousemove (object sender, MouseEventArgs e)
- {
- if (Currentstroke! = null)
- {
- Each time the mouse is moved, the corresponding points are collected.
- CURRENTSTROKE.STYLUSPOINTS.ADD (E.stylusdevice.getstyluspoints (mypresenter));
- }
- }
- }
- }
Windows Phone Development (21): Make a simple drawing board