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

时间:2015-03-12 04:58:47

标签: xaml windows-phone-8.1

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

我有XAML的REctangle:

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

在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;
        }
    }

如何在用户退出事件时移动对象whitout?

1 个答案:

答案 0 :(得分:0)

我假设通过投掷&#39;你的意思是你想要删除矩形的惯性方面?在这种情况下,从XAML代码中删除ManipulationMode setter,并在页面的构造函数(C#)中插入此行:

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

这应该消除你所谈论的惯性效应。但是作为一个侧面说明,这种移动UIElements的方法会给你一个相当恼人的延迟。我不久前遇到了类似的问题,通过使用不同的方法解决了问题:

Delay in drag/drop of UIElement in Windows Phone 8.1