Implementing handwriting in Silverlight2 Beta2

Source: Internet
Author: User

Imagine the process we write on paper, we need a piece of paper and a pen, and then we start writing the first word of a stroke, brushwork in the process we can according to the intensity of the stroke line to control the severity of the final pen. Then write down a stroke ....

In Silverlight2 this piece of paper is the InkPresenter control, the InkPresenter control as a set of strokes (Stroke) of the container for the real ink, Ink refers to the pen, touch screen and mouse input handwriting or the content of the painting. The Ink in Silverlight consists of StrokeCollection objects, strokecollection objects consist of different stroke objects. Each stroke corresponds to the press, move, and lift sequence of a pen. Stroke can be a point, a straight line, or even a curve. Each stroke consists of a StylusPointCollection object that has a different styluspoint composition. The StylusPoint object is a collection when the pen touches and moves with the digital converter. We can set the color, width, contour color and so on by the DrawingAttributes property of the object.

The following figure illustrates the structure of the InkPresenter:

InkPresenter does not support the use of stroke,strokecollection tags within the control. You can only control it in a programmatic way. Here's a simple example to illustrate. The more critical event in the InkPresenter control is MouseLeftButtonDown, Mousemove,mouseleftbuttonup, when InkPresenter receives the MouseLeftButtonDown event, You need to create a new stroke in memory and add it to the StrokeCollection, and when MouseMove we will styluspoints to stroke. End stroke in MouseLeftButtonUp event. We create a Silverlight project and add the following code to the Page.xaml:

<UserControl x:Class="SilverlightApplication2.Page"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Width="400" Height="300">
  <Grid x:Name="LayoutRoot" Background="White">
     <Rectangle x:Name="inkBorder" Width="346" Height="234" Stroke="#FF000000"
     Canvas.Top="25" Canvas.Left="25" RadiusX="25" RadiusY="25"/>
    <InkPresenter x:Name="inkP" Width="344" Height="232" Canvas.Left="25" Canvas.Top="34"
     MouseLeftButtonDown="inkP_MouseLeftButtonDown" MouseLeftButtonUp="inkP_MouseLeftButtonUp"
     MouseMove="inkP_MouseMove" Background="LightBlue">
    </InkPresenter>
   </Grid>
</UserControl>

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.