Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 5054 |  Welcome, Guest!   Register  Login
Home > Articles > WPF > Windows 7 Multitouch Application Development (Part - I)

Windows 7 Multitouch Application Development (Part - I)

3 vote(s)
Rating: 4.33 out of 5
Article posted by Kunal2383 on 3/6/2010 | Views: 7861 | Category: WPF | Level: Beginner red flag


Windows 7 came up with lots of goodies including better resource management, better performance, jumplist management, multitouch functionality & many more. Here I will discuss on developing a simple multitouch application using .Net 3.5 SP1.

Download


 Download source code for Windows 7 Multitouch Application Development (Part - I)


Introduction
Windows 7 came up with lots of goodies including better resource management, better performance, jumplist management, multitouch functionality & many more. Here I will discuss on developing a simple multitouch application using .Net 3.5 SP1. 

Prerequisite
Before doing anything you have to download the Windows 7 Multitouch API. You can download it from here. Extract the downloaded zip file to your local hard drive. Be sure that, you are using Windows 7 & you have a multitouch enabled screen to test it out. 

XAML Implementation

Create a WPF application using Visual Studio 2008. This will automatically add a XAML file named Window1.xaml for you. Now add an image to your solution directory & insert it in the XAML. Now your Window1.xaml will look something like this: 

<Grid>
<Image Source="images/Hydrangeas.jpg"/>
</
Grid>

Add RenderTransform to the image so that, we can scale or rotate the image properly. This will produce XAML similar to this: 

<Grid>
<
Image Source="images/Hydrangeas.jpg" RenderTransformOrigin="0.5,0.5" Width="400">
<
Image.RenderTransform>
<
TransformGroup>
<
ScaleTransform x:Name="trScale" ScaleX="1" ScaleY="1"/>
<
RotateTransform x:Name="trRotate" Angle="0"/>
<
TranslateTransform x:Name="trTranslate" X="0" Y="0"/>
<
SkewTransform AngleX="0" AngleY="0"/>
</
TransformGroup>
</
Image.RenderTransform>
</
Image>
</
Grid>

Use proper names when you are adding different types of transform to the transform group. It will be easier for you to handle it from the code behind file. Run your application. This will open up your Window with an image inside it. If you want to drag or rotate the image this will not work because we haven’t integrated the functionality yet.


Code Implementation

Add two project references i.e. “Windows7.Multitouch” & “Windows7.Multitouch.WPF” from the extracted zip folder to your solution. These are the managed API codes for multitouch application development. Go to your Window1.xaml.cs & be sure that following namespaces are already included. You may have to add some of them. 
using System; 
using System.Windows;
using Windows7.Multitouch;
using Windows7.Multitouch.Manipulation;
using Windows7.Multitouch.WPF;

Create two private members inside your partial class: 

// object of a .Net Wrapper class for processing multitouch manipulation 
private ManipulationProcessor manipulationProcessor = new ManipulationProcessor(ProcessorManipulations.ALL);

// boolean value to check whether you have a multitouch enabled screen
private static bool IsMultitouchEnabled = TouchHandler.DigitizerCapabilities.IsMultiTouchReady;

Now inside the Window Loaded event write the following lines of code: 

// check to see whether multitouch is enabled 
if (IsMultitouchEnabled)
{
// enables stylus events for processor manipulation
Factory.EnableStylusEvents(this);

// add the stylus events
StylusDown += (s, e) =>
{
manipulationProcessor.ProcessDown((uint)e.StylusDevice.Id, e.GetPosition(this).ToDrawingPointF());
};
StylusUp += (s, e) =>
{
manipulationProcessor.ProcessUp((uint)e.StylusDevice.Id, e.GetPosition(this).ToDrawingPointF());
};
StylusMove += (s, e) =>
{
manipulationProcessor.ProcessMove((uint)e.StylusDevice.Id, e.GetPosition(this).ToDrawingPointF());
};

// register the ManipulationDelta event with the manipulation processor
manipulationProcessor.ManipulationDelta += ProcessManipulationDelta;

// set the rotation angle for single finger manipulation
manipulationProcessor.PivotRadius = 2;
}

Write your logic inside the manipulation event handler implementation block. Here I will do rotation, scaling & positioning of the image. Here is my code: 

private void ProcessManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
trTranslate.X += e.TranslationDelta.Width;
trTranslate.Y += e.TranslationDelta.Height;

trRotate.Angle += e.RotationDelta * 180 / Math.PI;

trScale.ScaleX *= e.ScaleDelta;
trScale.ScaleY *= e.ScaleDelta;
}


Conclusion
From the ManipulationDeltaEventArgs you can get various values & depending upon them you can implement your functionality in this block. TranslateTransform will position the image, RotateTransform will do the rotation & the ScaleTransform will resize the image. Run your project to test your first multitouch application. 


Download Sample Application 


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:3 year(s)
Home page:http://www.kunal-chowdhury.com
Member since:Monday, March 01, 2010
Level:Starter
Status: [Member]
Biography:He is currently working as a Silverlight application developer. Has a very good skill over C#, XAML, Silverlight & WPF. He has a good working experience in Windows 7 application (including Multitouch) development.

During his professional career he worked in various technologies & delivered quality output. He never hesitates to take up challenges & work on the latest technologies in Microsoft platform.

He attended various software development competition & achieved different awards.

He is presently focusing on the RIA (Silverlight & WPF) & willing to become a Technology Specialist in Microsoft platform. Learning newer things, Blog posting & helping others in forums is one of his regular activity.

Specialties: Silverlight Application Development, WPF Application Development, Windows 7 Application Development
 Responses
Posted by: Mrplink | Posted on: 24 Aug 2011 11:07:40 AM | Points: 25


Is there any simulator for running multitouch application on normal windows7 desktop?

Pls reply

>> Write Response - Respond to this post and get points
Related Posts

In this article I have showed how you can build pluggable Resources for styles, Languages or any static objects etc. Therefore building a new style doesn't hampers your code and you can easily plugin any new style to the application inspite it is already in production environment. I have added a language converter tool, which will generate multi lingual resources for you.

Ribbon Bar was introduced with Office 2007 has lately been very much popular for latest UI development. Microsoft has replaced the old Menu based application tool with more flexible and easy to learn Ribbon strips in many of its applications. So it is time for other developers to use it in their own applications. The Ribbon UI feature that was released recently bridges this to us.

In this article, I have specified how you could use Style, Triggers and animation in your WPF application to make your application more attractive, interactive and user friendly.

WPF 4.0 comes with certain cool features like changing Selection Brush for text selection, Changing color of Caret etc. I am going to discuss those in this article

WPF introduces a new property system which is enhanced by Dependency property. There are many improvements of Dependency Property over CLR properties. In this article I have discussed how you could create your own Dependency Property and to work with various features of it.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2012 7:57:54 AM