Hi,
I am working on multitouch application. My requirement is that I am using one image as background which should be static and other images are used to move on the Background image.
1. First I have downloaded the code which was in the blog and i saw that where ever i can touch the screen it is moving but i want when i touch the image then only it have to move.
2. I have used your code and modified according to my requirement.But no image is moving after doing the modifications.
Can you please help me regarding this.Below is my code:
<Window x:Class="Win7MultitouchDemo.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Windows 7 MultiTouch Demo" Height="600" Width="800" WindowState="Maximized">
<Canvas x:Name="holder" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="300" Width="500">
<Canvas.Background>
<ImageBrush ImageSource="images/Water lilies.jpg" Stretch="UniformToFill" />
</Canvas.Background>
<Image Source="images/Hydrangeas.jpg" RenderTransformOrigin="0.5,0.5" Width="200" Canvas.Left="307" Canvas.Top="-1" Height="150">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="tr1Scale" ScaleX="1" ScaleY="1"/>
<RotateTransform x:Name="tr1Rotate" Angle="0"/>
<TranslateTransform x:Name="tr1Translate" X="0" Y="0"/>
<SkewTransform AngleX="0" AngleY="0"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Image Source="images/Hydrangeas.jpg" RenderTransformOrigin="0.5,0.5" Width="200" Canvas.Left="309" Canvas.Top="148" Height="150" StretchDirection="Both">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="tr2Scale" ScaleX="1" ScaleY="1"/>
<RotateTransform x:Name="tr2Rotate" Angle="0"/>
<TranslateTransform x:Name="tr2Translate" X="0" Y="0"/>
<SkewTransform AngleX="0" AngleY="0"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
</Canvas>
</Window>
Cs Code:
using System;
using System.Windows;
using Windows7.Multitouch;
using Windows7.Multitouch.Manipulation;
using Windows7.Multitouch.WPF;
namespace Win7MultitouchDemo
{
public partial class Window1 : Window
{
private ManipulationProcessor manipulationProcessor = new ManipulationProcessor(ProcessorManipulations.ALL);
private static bool IsMultitouchEnabled = TouchHandler.DigitizerCapabilities.IsMultiTouchReady;
public Window1()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Window1_Loaded);
}
void Window1_Loaded(object sender, RoutedEventArgs re)
{
if (IsMultitouchEnabled)
{
Factory.EnableStylusEvents(this);
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()); };
manipulationProcessor.ManipulationDelta += ProcessManipulationDelta;
manipulationProcessor.PivotRadius = 2;
}
}
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;
tr1Translate.X += e.TranslationDelta.Width;
tr1Translate.Y += e.TranslationDelta.Height;
tr1Rotate.Angle += e.RotationDelta * 180 / Math.PI;
tr1Scale.ScaleX *= e.ScaleDelta;
tr1Scale.ScaleY *= e.ScaleDelta;
tr2Translate.X += e.TranslationDelta.Width;
tr2Translate.Y += e.TranslationDelta.Height;
tr2Rotate.Angle += e.RotationDelta * 180 / Math.PI;
tr2Scale.ScaleX *= e.ScaleDelta;
tr2Scale.ScaleY *= e.ScaleDelta;
}
}
}