0

I'm new C# beginer. I want to prevent throwing XAML's object by manipulation event. My app is developed in Windows Phone 8.1 RT.

I have XAML's REctangle:

<Canvas x:Name="MyCanvas" Background="White">
        <Rectangle Name="TestRectangle"
          Width="100" Height="200" Fill="Blue" 
          ManipulationMode="All"/>
</Canvas>

In MainPage:

public MainPage()
    {
        this.InitializeComponent();
        // Handle manipulation events.
        TestRectangle.ManipulationDelta += Drag_ManipulationDelta;
        dragTranslation = new TranslateTransform();
        TestRectangle.RenderTransform = this.dragTranslation;

        this.NavigationCacheMode = NavigationCacheMode.Required;
    }
void Drag_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        // Move the rectangle.
            dragTranslation.X += e.Delta.Translation.X;
            dragTranslation.Y += e.Delta.Translation.Y;
    }

    private void TestRectangle_PointerPressed(object sender,
PointerRoutedEventArgs e)
    {
        Rectangle rect = sender as Rectangle;

        // Change the size of the Rectangle
        if (null != rect)
        {
            rect.Width = 250;
            rect.Height = 150;
        }
    }
    private void TestRectangle_PointerReleased(object sender,
PointerRoutedEventArgs e)
    {
        Rectangle rect = sender as Rectangle;

        // Reset the dimensions on the Rectangle
        if (null != rect)
        {
            rect.Width = 200;
            rect.Height = 100;
        }
    }
    private void TestRectangle_PointerExited(object sender,
PointerRoutedEventArgs e)
    {
        Rectangle rect = sender as Rectangle;

        // Finger moved out of Rectangle before the pointer exited event
        // Reset the dimensions on the Rectangle
        if (null != rect)
        {
            rect.Width = 200;
            rect.Height = 100;
        }
    }

How to move object whitout throwing when user exit event ?

Jose Luis
  • 3,307
  • 3
  • 36
  • 53
Secret
  • 15
  • 7

1 Answers1

0

I'm assuming that by 'throwing' you mean you want to remove the inertial aspect of your rectangle? In that case remove the ManipulationMode setter from your XAML code and insert this line in your page's constructor (C#):

TestRectangle.ManipulationMode = ManipulationMode.TranslateX | ManipulationMode.TranslateY;

That should remove the intertial effect you're talking about. As a side note though, this method of moving UIElements will give you a pretty annoying lag. I faced a similar problem a little while ago and the issue was resolved by using a different approach:

Delay in drag/drop of UIElement in Windows Phone 8.1

Community
  • 1
  • 1
Ali250
  • 652
  • 1
  • 5
  • 19