I want to know how can I detect a Zoom/pinch gesture made on UserControl? Following is my XAML code. How can i detect this in "Grid_OnManipulationDelta" or "Grid_OnManipulationCompleted" methods? Thanx for the help in advance.
<UserControl x:Class="HCMainWPF.Views.MainView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:views="clr-namespace:HCMainWPF.Views" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Name="ZMainView">
<Canvas x:Name="grid">
<Canvas.RenderTransform>
<ScaleTransform x:Name="zoom" ScaleX="1" ScaleY="1" />
</Canvas.RenderTransform>
<Canvas.Triggers>
<EventTrigger RoutedEvent="Grid.ManipulationCompleted">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="00:00:02" From="320" Storyboard.TargetName="ZMainView"
Storyboard.TargetProperty="Height" To="960"/>
<DoubleAnimation Duration="00:00:02" From="270" Storyboard.TargetName="ZMainView"
Storyboard.TargetProperty="Width" To="810"/>
<DoubleAnimation Duration="00:00:02" From="1" Storyboard.TargetName="zoom"
Storyboard.TargetProperty="ScaleX" To="3"/>
<DoubleAnimation Duration="00:00:02" From="1" Storyboard.TargetName="zoom"
Storyboard.TargetProperty="ScaleY" To="3"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Canvas.Triggers>
<Grid Height="280" Width="280" IsManipulationEnabled="True"
ManipulationStarting="Grid_OnManipulationStarting"
ManipulationDelta="Grid_OnManipulationDelta"
ManipulationCompleted="Grid_OnManipulationCompleted">
<Grid.RowDefinitions>
<RowDefinition Height="1.66*"/>
<RowDefinition Height="1.66*"/>
<RowDefinition Height="1.66*"/>
<RowDefinition Height="1.66*"/>
<RowDefinition Height="1.66*"/>
<RowDefinition Height="1.66*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3.33*"/>
<ColumnDefinition Width="3.33*"/>
<ColumnDefinition Width="3.33*"/>
</Grid.ColumnDefinitions>
</Grid>
</Canvas>
</UserControl>
In short, yes. The quickest way to get up and running with a pinch/zoom gesture is to attach the 'TranslateZoomRotateBehavior' to the usercontrol or element you want to control. This will allow you to use single and multitouch events to control the pan, scale and rotation of an element.
If you want to do this manually, then I suggest you have a look at a custom version of this behaviour I've posted on Codeplex.
In particular, the ManipulationDeltaHandler in this class.
Usage: