Hi all,
My application is running on touchscreen panel. I have rectangle in my WPF application and fill it with image. I already handle the manipulation of moving and resize the rectangle. But I don't know how to reset the image so it goes to default position and size.
My XAML:
<ScrollViewer Margin="29.64,102.905,27.539,30.601" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" Name="sv_map" Width="1190" Height="750">
<WrapPanel Height="750" Width="1190" Name="wp_map">
<Rectangle x:Name="rec_map" RadiusY="20" RadiusX="20" IsManipulationEnabled="True" Height="750" Width="1190">
<Rectangle.Fill>
<ImageBrush ImageSource="/MAIN_IAB;component/Images/default.jpg"/>
</Rectangle.Fill>
</Rectangle>
</WrapPanel>
</ScrollViewer>
My source code handling rectangle interaction:-
Private Sub rec_map_ManipulationDelta(ByVal sender As Object, ByVal e As System.Windows.Input.ManipulationDeltaEventArgs) Handles rec_map.ManipulationDelta
ScreenTimer.Stop()
Dim shapeBounds As Rect = rec_map.RenderTransform.TransformBounds(New Rect(rec_map.RenderSize))
Dim containingRect As New Rect((CType(Me, FrameworkElement)).RenderSize)
Dim manipDelta As ManipulationDelta = e.DeltaManipulation
If e.IsInertial AndAlso (Not containingRect.Contains(shapeBounds)) Then
e.Complete()
End If
Dim rectsMatrix As Matrix = (CType(rec_map.RenderTransform, MatrixTransform)).Matrix
Dim rectManipOrigin As Point = rectsMatrix.Transform(New Point(rec_map.ActualWidth / 2, rec_map.ActualHeight / 2))
rectsMatrix.ScaleAt(manipDelta.Scale.X, manipDelta.Scale.Y, rectManipOrigin.X, rectManipOrigin.Y)
rectsMatrix.Translate(manipDelta.Translation.X, manipDelta.Translation.Y)
rec_map.RenderTransform = CType(New MatrixTransform(rectsMatrix).GetAsFrozen(), MatrixTransform)
e.Handled = True
ScreenTimer.Start()
End Sub
Private Sub rec_map_ManipulationInertiaStarting(ByVal sender As Object, ByVal e As System.Windows.Input.ManipulationInertiaStartingEventArgs) Handles rec_map.ManipulationInertiaStarting
ScreenTimer.Stop()
e.TranslationBehavior.DesiredDeceleration = 10 * 96.0 / (1000.0 * 1000.0)
e.ExpansionBehavior.DesiredDeceleration = 0.1 * 96 / 1000.0 * 1000.0
e.RotationBehavior.DesiredDeceleration = 720 / (1000.0 * 1000.0)
e.Handled = True
ScreenTimer.Start()
End Sub
Private Sub rec_map_ManipulationStarting(ByVal sender As Object, ByVal e As System.Windows.Input.ManipulationStartingEventArgs) Handles rec_map.ManipulationStarting
e.ManipulationContainer = Me
e.Handled = True
End Sub
I have create one button for Reset the image in case User drag and release the image and the image is sliding of the grid and unable to retrieve back unless I go back and come to the page again(have test this situation). But I don't know how to do this for control that have the manipulation enabled.