C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » WPF »

Windows 7 Multitouch Application Development (Part - II)


Posted Date: 09 Sep 2009    Resource Type: Articles    Category: WPF
Author: Kunal ChowdhuryMember Level: Silver    
Rating: 1 out of 5Points: 10



In my last post Windows 7 Multitouch Application Development (Part - I), I described about how to handle multitouch image manipulation in Windows 7 which gives a very basic idea on the multitouch development. That code uses multitouch manipulation for the entire screen. If there are multiple images in the screen this will raise event for all.

In this post, I will show you how to manage multitouch events for all the images separately. See one of such kind of image manipulation demo here.

For this we have to assign a unique touch-id for each finger on the screen. As long as the finger touches the screen the associated touch-id will remain same for that particular finger. If the user releases his finger the system will release the touch-id & that can be again assign by the system automatically on next touch. So, how can we get the touch-id? You can get the same from the StylusEventArgs (i.e. args.StylusDevice.Id). The stylus device will automatically generate this ID for each touch, only thing is you have to assign it with the respective finger touch.

First of all, we will create an UserControl which will consist of a single Image & XAML code for it’s RenderTransform. The same thing we did in the previous post which was inside the Window, but here it will be inside the UserControl (Picture class). Create a DependencyProperty to assign the ImageLocation dynamically.


<UserControl x:Class="Windows7MultitouchDemo.Picture"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Image Source="{Binding Path=ImageLocation}" Stretch="Fill" Width="Auto"
Height="Auto" RenderTransformOrigin="0.5, 0.5">
<Image.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="trRotate"/>
<ScaleTransform x:Name="trScale"/>
<TranslateTransform x:Name="trTranslate"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
</UserControl>


To track the multi-touch simultaneously for the above “Picture” usercontrol, you can use the PictureTracker class which comes with the Windows 7 Training Kit. You can download it from Microsoft Site. It looks similar to this:


///
/// Track a single picture
///

public class PictureTracker
{
private Point _prevLocation;
public Picture Picture { get; set; }
public void ProcessDown(Point location)
{
_prevLocation = location;
}
public void ProcessMove(Point location)
{
Picture.X += location.X - _prevLocation.X;
Picture.Y += location.Y - _prevLocation.Y;
_prevLocation = location;
}
public void ProcessUp(Point location)
{
//Do Nothing, We might have another touch-id that is
//still down
}
}



Now, we have to store all the active touch-ids associated with the PictureTracker class. So, we will use a dictionary for that. We will use the same PictureTrackerManager class which again comes with the Windows 7 Training Kit.


private readonly Dictionary _pictureTrackerMap;


Create an instance of the PictureTrackerManager class inside your Window1.xaml.cs & register the stylus events with the PictureTrackerManager events. So now whenever a touch occurs on the Picture, the PictureTrackerManager will first find the associated touch-id for the respective instance and raise event to process the same.


//Register for stylus (touch) events
StylusDown += _pictureTrackerManager.ProcessDown;
StylusUp += _pictureTrackerManager.ProcessUp;
StylusMove += _pictureTrackerManager.ProcessMove;



Reference: Windows 7 Training Kit
Download Sample Application

For more details, visit http://kunal2383.blogspot.com/2009/09/windows-7-multitouch-application.html



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
WPF  .  Windows Presentation Foundation  .  Windows 7  .  Multitouch  .  .Net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: WPF Multitrigger
Previous Resource: WPF BorderBrush
Return to Discussion Resource Index
Post New Resource
Category: WPF


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use