edu*_*911 5 windows-phone-7 windows-phone panorama-control
我正在构建一个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;
}
Run Code Online (Sandbox Code Playgroud)
当更新任何这些文本框时,屏幕会"跳转"回主页面.有点不好的经历.
也许这是正常的?知道用户是否试图"滑动"到下一页是否有事件可以吸引?
提前致谢.
嗯,这感觉就像是黑客攻击。但我通过参加一些活动得到了我想要的延迟。如果我应该使用其他事件(例如 mousedown/mouseup),请告诉我。再说一遍,这是一个 hack,但有效。
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;
});
}
Run Code Online (Sandbox Code Playgroud)
我现在要做的就是检查代码中的 isChangingPage 布尔值。并将其传递给事件等。
| 归档时间: |
|
| 查看次数: |
468 次 |
| 最近记录: |