Xaml Windows Phone 8.1 RT:如何防止操纵事件抛出对象?

Xaml Windows Phone 8.1 RT:如何防止操纵事件抛出对象?,xaml,windows-phone-8.1,Xaml,Windows Phone 8.1,我是新来的C#beginer。我想防止通过操纵事件抛出XAML的对象。我的应用程序是在Windows Phone 8.1 RT中开发的 我有XAML的矩形: <Canvas x:Name="MyCanvas" Background="White"> <Rectangle Name="TestRectangle" Width="100" Height="200" Fill="Blue" ManipulationMode="

我是新来的C#beginer。我想防止通过操纵事件抛出XAML的对象。我的应用程序是在Windows Phone 8.1 RT中开发的

我有XAML的矩形:

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

当用户退出事件时,如何在不抛出的情况下移动对象?

我假设“抛出”是指要移除矩形的惯性部分?在这种情况下,从XAML代码中删除
operationmode
setter,并在页面的构造函数(C#)中插入此行:

这应该可以消除你所说的相互影响。不过,作为旁注,这种移动UIElements的方法会给您带来相当恼人的延迟。不久前,我遇到了一个类似的问题,通过使用不同的方法解决了这个问题:


我明白了。非常感谢,代码很好:)!
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;
        }
    }
TestRectangle.ManipulationMode = ManipulationMode.TranslateX | ManipulationMode.TranslateY;