Windows Phone 7 touch programming-single point of touch with touch. framereported event

Source: Internet
Author: User

On WP7, Silverlight also supports multi-touch. There are two different programming modes:

1. Low-Level touch. framereported events

2. Use the uielement class to define three events: manipulationstarted, manipulationdelta, and manipulationcompleted.

I,

The first low-level touch programming is to use a class touchpoint. an instance of a touchpoint represents a specific finger to touch the screen.

Four attributes of touchpoint:
• Action type-enumeration of touchaction, which has four values: down, move, and up, indicating that the fingers are pressed, moved, and left.
• Type of the position-the position of the point, with the upper left corner as the reference point.
• Size Type-size, supporting contact area (finger pressure), but Windows 7 does not return phone useful values.
• Type of the contact device.

The touchdevice object has two read-only attributes:
• The ID int type is used to differentiate fingers. A specific finger has a unique Test ID to trigger all the upstream and downstream events.

• Directlyover uielement type, the top-level element of your finger.

Use touch. framereported event processingProgram:
Touch. framereported + = ontouchframereported;

The ontouchframereported method format is as follows:
Void ontouchframereported (Object sender, touchframeeventargs ARGs)

{
...

}

The touchframeeventargs ARGs event has three methods:

• Gettouchpoints (refelement) returns a touchpointcollection to obtain a set of multiple touchpoints
• Getprimarytouchpoint (refelement) returns a touchpoint to obtain the first finger contact point.
• Suspendmousepromotionuntiltouchup ()

The returned value is relative to the transmitted Parameter Element Contact Point.

When null is passed, gettouchpoints obtains the upper left corner of the position attribute relative to the application.

Changing the font color with single touch

 

Code

  <  Phone: phoneapplicationpage
X: Class = "Silverlighttouchhello. mainpage"
Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: Phone = "CLR-namespace: Microsoft. Phone. controls; Assembly = Microsoft. Phone"
Xmlns: Shell = "CLR-namespace: Microsoft. Phone. Shell; Assembly = Microsoft. Phone"
Xmlns: d = "Http://schemas.microsoft.com/expression/blend/2008"
Xmlns: MC = "Http://schemas.openxmlformats.org/markup-compatibility/2006"
Fontfamily = "{Staticresource phonefontfamilynormal }"
Fontsize = "{Staticresource phonefontsizenormal }"
Foreground = "{Staticresource phoneforegroundbrush }"
Supportedorientations = "Portraitorlandscape" Orientation = "Portrait"
MC: ignorable = "D" D: designwidth = "480" D: designheight = "768"
Shell: systemtray. isvisible = "True" >

<! -- Layoutroot contains the root grid where all other page content is placed -->
< Grid X: Name = "Layoutroot" Background = "Transparent" >
< Grid. rowdefinitions >
< Rowdefinition Height = "Auto" />
< Rowdefinition Height = "*" />
</ Grid. rowdefinitions >

<! -- Titlepanel contains the name of the application and page title -->
< Stackpanel X: Name = "Titlepanel" Grid. Row = "0" Margin =" >
< Textblock X: Name = "Applicationtitle" Text = "Silverlight touch hello" Style = "{Staticresource phonetextnormalstyle }" />
< Textblock X: Name = "Pagetitle" Text = "Main page" Margin = "9,-7, 0, 0" Style = "{Staticresource phonetexttitle1style }" />
</ Stackpanel >

<! -- Contentpanel-place additional content here -->
< Grid X: Name = "Contentpanel" Grid. Row = "1" Margin = "12, 0, 12, 0" >
< Textblock Name = "Txtblk"
Text = "Hello, Windows Phone 7! "
Padding = "0 22"
Horizontalalignment = "Center"
Verticalalignment = "Center" />
</ Grid >
</ Grid >

<! -- Sample Code showing usage of ApplicationBar
<Phone: phoneapplicationpage. ApplicationBar>
<Shell: ApplicationBar isvisible = "true" ismenuenabled = "true">
<Shell: applicationbariconbutton X: Name = "appbar_button1" iconuri = "/images/appbar_button1.png" text = "button 1"> </shell: applicationbariconbutton>
<Shell: applicationbariconbutton X: Name = "appbar_button2" iconuri = "/images/appbar_button2.png" text = "button 2"> </shell: applicationbariconbutton>
<Shell: ApplicationBar. menuitems>
<Shell: applicationbarmenuitem X: Name = "menuitem1" text = "menuitem 1"> </shell: applicationbarmenuitem>
<Shell: applicationbarmenuitem X: Name = "menuitem2" text = "menuitem 2"> </shell: applicationbarmenuitem>
</Shell: ApplicationBar. menuitems>
</Shell: ApplicationBar>
</Phone: phoneapplicationpage. ApplicationBar>
-->


</ Phone: phoneapplicationpage >
Code

  Using  System;
Using System. Windows. input;
Using System. Windows. Media;
Using Microsoft. Phone. controls;

Namespace Silverlighttouchhello
{
Public Partial Class Mainpage: phoneapplicationpage
{
Random Rand = New Random ();
Brush originalbrush;

Public Mainpage ()
{
Initializecomponent ();
Originalbrush = Txtblk. Foreground;
Touch. framereported + = Ontouchframereported;
}

Void Ontouchframereported ( Object Sender, touchframeeventargs ARGs)
{
Touchpoint primarytouchpoint = Args. getprimarytouchpoint ( Null );

If (Primarytouchpoint ! = Null && Primarytouchpoint. Action = Touchaction. down)
{
If (Primarytouchpoint. touchdevice. directlyover = Txtblk)
{
Txtblk. Foreground = New Solidcolorbrush (
Color. fromargb ( 255 ,( Byte ) Rand. Next ( 256 ),
( Byte ) Rand. Next ( 256 ),
( Byte ) Rand. Next ( 256 )));
}
Else
{
Txtblk. Foreground = Originalbrush;
}
}
}
}
}

 

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.