可能重复:
In windows phone 7, ManipulationDelta event does not work as expected.
我尝试在Windows Phone 7应用程序中使用ManipulationDelta帮助清除和更新Canvas的子项,但似乎它不起作用,这里是代码:
<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>
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();
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);
}
}
矩形将跟随手指,如果我将代码从“var c = new Rectangle();”更改为“var c = rectangle //已存在的对象”,则拖动矩形时将会多次引发“ManipulationDelta”事件“,否则,”ManipulationDelta“事件只会被提升一次。有人知道问题在哪里吗?
问候语,
约翰尼