windows-phone-7 – 为什么WP7全景页面会在更新时跳回?
我正在构建一个GPS相关的应用程序,显示其他计算中的坐标.我的演示代码设置为每秒触发事件.
每当我更新主页面UI(例如,具有计算的纬度的文本框)时,它都可以正常工作. 问题是如果我试图从一侧“轻弹”到另一侧,更改页面.在“轻弹”的过程中,如果要更新文本框,它会将主页面跳回到视图中. 没有视频很难在文本中解释.但想象一下,点击n-holding,然后轻轻地拉开全景屏幕 – 比如说,看看下一页,但还没有翻转.好吧,如果文本框在那段时间内要更新,你将松开鼠标点击保持,它会跳回到主页面. 一旦你到达下一页,它就会停留,我可以看到上一页的溢出更新.没什么大不了的.但它只是试图进入下一页. 我是WP7 / Silverlight的新手,所以我一直在尝试使用Dispatcher来提高响应速度.无论我做什么(使用Dispatcher),都会发生这种情况.所以,我猜这与更新的UI有关. 一些小代码总能帮助: void GeoWatcher_PositionChanged(object sender,GeoPositionChangedEventArgs<GeoCoordinate> e) { Deployment.Current.Dispatcher.BeginInvoke(() => MyPositionChanged(e)); } void MyPositionChanged(GeoPositionChangedEventArgs<GeoCoordinate> e) { var model = GeoProcessor.GetPosition(e.Position); latitude.Text = model.Latitude; longitude.Text = model.Longitude; altitude.Text = model.Altitude; accuracy.Text = model.Accuracy; direction.Text = model.Direction; speed.Text = model.Speed; speedAvg.Text = model.SpeedAvg; } 当更新任何这些文本框时,屏幕会“跳转”回主页面.有点不好的经历. 也许这是正常的?知道用户是否试图“滑动”到下一页是否有事件可以吸引? 提前致谢. 解决方法
嗯,这感觉就像一个黑客.但我通过勾结一些事件得到了我想要的延迟.如果我应该使用其他事件(例如mousedown / mouseup),请告诉我.再次,这是一个黑客,但有效.
bool isChangingPage = false; bool isCompleting = false; public MainPage() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MainPage_Loaded); this.ManipulationStarted += new EventHandler<ManipulationStartedEventArgs>(MainPage_ManipulationStarted); this.ManipulationCompleted += new EventHandler<ManipulationCompletedEventArgs>(MainPage_ManipulationCompleted); } void MainPage_ManipulationStarted(object sender,ManipulationStartedEventArgs e) { isChangingPage = true; } void MainPage_ManipulationCompleted(object sender,ManipulationCompletedEventArgs e) { if (isCompleting) return; isCompleting = true; Deployment.Current.Dispatcher.BeginInvoke(() => { Thread.Sleep(1000); isChangingPage = false; isCompleting = false; }); } 我现在要做的就是检查代码中的isChangingPage布尔值.并将其传递给事件等 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |