在Windows Phone 7的,如预期ManipulationDelta事件不起作用 [英] In windows phone 7, ManipulationDelta event does not work as expected

查看:218
本文介绍了在Windows Phone 7的,如预期ManipulationDelta事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在code重现它,XAML:

This is the code to reproduce it, xaml:

<phone:PhoneApplicationPage 
    x:Class="WindowsPhoneApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Canvas x:Name="LayoutRoot" Background="Gray" Width="600" Height="800">
        <!--ContentPanel - place additional content here-->
        <Rectangle Name="rectangle" Width="100" Height="100" Fill="Red" />
    </Canvas>
</phone:PhoneApplicationPage>

这是code-背后:

and this is the code-behind:

public partial class MainPage : PhoneApplicationPage
    {
        private double translationX = 0.0;
        private double translationY = 0.0;

        // Constructor
        public MainPage()
        {
            InitializeComponent();
            LayoutRoot.ManipulationDelta += this.PhoneApplicationPage_ManipulationDelta;
        }

        void PhoneApplicationPage_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            this.translationX += e.DeltaManipulation.Translation.X;
            this.translationY += e.DeltaManipulation.Translation.Y;

            System.Diagnostics.Debug.WriteLine(string.Format("{0},{1}", this.translationX, this.translationY));

            var c = new Rectangle();
            //var c = rectangle;
            c.Width = 100;
            c.Height = 100;
            c.Fill = new SolidColorBrush(Colors.Red);
            c.SetValue(Canvas.LeftProperty, this.translationX);
            c.SetValue(Canvas.TopProperty, this.translationY);

            LayoutRoot.Children.Clear();
            LayoutRoot.Children.Add(c);
        }

    }

运行这个程序,拖动红色矩形,你会发现矩形只移动了一次,它不会按照你的手指(或鼠标指针)的运动。

Run this app, drag the red rectangle, you'll find that the rectangle only moves for one time, it does not follow the movement of your finger(or mouse pointer).

现在尝试更改下面两行code:

Now try to change the following two lines of code:

var c = new Rectangle();
//var c = rectangle;

这种形式:

//var c = new Rectangle();
var c = rectangle;

然后再运行它,它会按预期工作,该矩形会按照你的取景器(或鼠标指针)的运动,这是为什么?

then run it again, it'll work as expected, the rectangle will follow the movement of your finder(or mouse pointer),why is this?

感谢

推荐答案

这里的东西,这将有助于理解它。使用可创建矩形的新实例的版本,单击矩形的阻力之外,在屏幕上。有用。现在在XAML,设置IsHitTestVisible =假为矩形。现在,单击矩形并拖动里面,它也可以。很显然,矩形可以拦截一些操纵事件,而不是将其转发到LayoutRoot,而你需要做一些住宿这一点。

Here's something that will help to understand it. Using your version that creates new instances of Rectangle, click outside of the Rectangle and drag around the screen. It works. Now in the xaml, set IsHitTestVisible="False" for the Rectangle. Now click inside the Rectangle and drag, and it also works. It is clear that the Rectangle can intercept some manipulation events and not forward them to the LayoutRoot, and you need to make some accommodation for this.

理查德·胡

============ 这是应用程序中心

============ This is from App Hub

这篇关于在Windows Phone 7的,如预期ManipulationDelta事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆