WPF/Windows Phone: Use inkpresenter for painting

Source: Internet
Author: User

Update:

Updated for WPF: see WPF: painting with inkpresenter (update)

I used to write a Windows Phone 7 Article: Using framereported to do a simple drawing program, drawing in inkpresenter by using the touch framereporter event. This articleArticleIt uses the most basic mouse events and supports the erasure function. In Windows Phone, developers can only inkpresenter. However, for the WPF environment, you can use the more powerful inkpresenter encapsulation control inkcanvas. However, the examples in this article are all inkpresenter.

 

Running effect:

 

ProgramThe running logic closely revolves around the execution of the inkpresenter control in XAML. The specific environment may have some minor differences, but it is similar in general. Draw a basic mouse event defined by uielement, and add a stroke object to the strokes attribute of inkpresenter In the event. The stroke object includes a specific vertex, that is, a styluspoint object. In Windows Phone, directly using mouseeventargs. stylusdevice. getstyluspoints can directly return a styluspoint, which is more convenient to use. In WPF, mouseeventargs. stylusdevice is usually null. Therefore, you can only use the mouseeventargs. getposition method.

Secondly, a styluspointcollection object must be input for creating a stroke object in WPF, And the collection must contain a vertex, that is, the styluspoint object. Windows Phone does not have this restriction.

 

The erasure function is implemented through the hittest method of the strokecollection type. In WPF, hittest is more inclined to support the point. The strokecollection. hittest method is overloaded in the following WPF:

Public StrokecollectionHittest (PointPoint );

Public StrokecollectionHittest (Ienumerable<Point>Lassopoints,IntPercentagewithinlasso );

Public StrokecollectionHittest (Ienumerable<Point>Path,StylusshapeStylusshape );

Public StrokecollectionHittest (PointPoint,DoubleDiameter );

Public StrokecollectionHittest (RectBounds,IntPercentagewithinbounds );

In Windows Phone, you can only use the styluspointcollection object:

Public StrokecollectionHittest (StyluspointcollectionStyluspointcollection );

Therefore, when executing the erasure function, WPF can directly input the current vertex in the mousemove event for hittest. In Windows Phone, a collection of styluspointcollection needs to be recorded.

 

At last, the inkpresenter of WPF does not seem to respond to any mouse event. Therefore, you need to place a control (such as border) outside it as the mouse event access point.

 

The control is easy to use. You can use an inkpresenter to create the inner inkdrawing type (the execution of WPF and Windows Phone is slightly different), and then you can draw the chart. Its drawingattributes attribute sets the paint brush style. The ismousecaptureenabled and ismousedrawingenable attributes can be used to set whether to capture mouse events and whether to allow mouse drawing. The default values are true. The last mode attribute can be set to draw and erase modes.

 

 

The current version of the program andSource codeDownload

Download Page

Note: the link is the Microsoft SkyDrive page. When downloading, use a browser to download it directly. Some download tools may not be available for downloading.

SourceCodeEnvironment:

WPF: Microsoft Visual Studio express 2012 for Windows Desktop

Windows Phone: Microsoft Visual Studio express 2012 for Windows Phone

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.