WPF multi-touch Development: Inertia effects (inertia)

Source: Internet
Author: User
Tags touch

From the previous example, you can see that if you move your finger away from the screen while the picture is moving, the picture stops immediately, in which case WPF provides another inertia effect (inertia). It allows the UI unit to move more physically, more realistically, and more smoothly.

On the basis of the preceding code, additional manipulationinertiastarting events need to be added for <Canvas>.

<Canvas x:Name="touchPad" Background="Gray"
     ManipulationStarting="image_ManipulationStarting"
     ManipulationDelta="image_ManipulationDelta"
     ManipulationCompleted="image_ManipulationCompleted"
     ManipulationInertiaStarting="image_ManipulationInertiaStarting">

Image_manipulationinertiastarting Event content is the following code, respectively, Translationbehavior, Expansionbehavior, rotationbehavior settings, so that its Possess inertial characteristics.

private void image_ManipulationInertiaStarting(object  sender,
   ManipulationInertiaStartingEventArgs e)
{
   e.TranslationBehavior = new InertiaTranslationBehavior();
   e.TranslationBehavior.InitialVelocity =  e.InitialVelocities.LinearVelocity;
   e.TranslationBehavior.DesiredDeceleration = 10.0 * 96.0 /  (1000.0 * 1000.0);

   e.ExpansionBehavior = new InertiaExpansionBehavior();
   e.ExpansionBehavior.InitialVelocity =  e.InitialVelocities.ExpansionVelocity;
   e.ExpansionBehavior.DesiredDeceleration = 0.1 * 96 /  1000.0 * 1000.0;

   e.RotationBehavior = new InertiaRotationBehavior();
   e.RotationBehavior.InitialVelocity =  e.InitialVelocities.AngularVelocity;
   e.RotationBehavior.DesiredDeceleration = 720 / (1000.0 *  1000.0);
}

Program Demo

The following video can be seen in the manipulation, the picture has an inertial effect.

Video address: http://static.youku.com/v1.0.0122/v/swf/qplayer.swf? Videoids=xmtk4mjuyndaw&embedid=mti1ljy5lje0nc4zngi0otu2mzewmaj3d3cu Y25IBG9NCY5JB20CL2DUAWVSZWUVYXJJAGL2ZS8YMDEWLZA4LZE5L211BHRPLXRVDWNOLWL uzxj0aweuahrtba==&showad=0

SOURCE Download Address: Http://cid-c75f4e27adfe5bbc.office.live.com/self.aspx/GnieTech/WpfInertia.zip

Source: http://www.cnblogs.com/gnielee/

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.