Click here to Skip to main content
15,895,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
XML
<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:-
VB
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))
    ' Resize the Rectangle.  Keep it square
    ' so use only the X value of Scale.
    rectsMatrix.ScaleAt(manipDelta.Scale.X, manipDelta.Scale.Y, rectManipOrigin.X, rectManipOrigin.Y)
    '' Move the Rectangle.
    rectsMatrix.Translate(manipDelta.Translation.X, manipDelta.Translation.Y)
    ' Apply the changes to the Rectangle.
    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()
    ' Decrease the velocity of the Rectangle's movement
    e.TranslationBehavior.DesiredDeceleration = 10 * 96.0 / (1000.0 * 1000.0)

    ' Decrease the velocity of the Rectangle's resizing
    e.ExpansionBehavior.DesiredDeceleration = 0.1 * 96 / 1000.0 * 1000.0

    ' Decrease the velocity of the Rectangle's rotation rate
    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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900