我正在构建一个与 GPS 相关的应用程序,它在其他计算中显示坐标。我的演示代码设置为每秒触发事件。
每当我更新主页 UI(例如,带有计算纬度的文本框)时,它都可以正常工作。
问题是,如果我尝试从一侧“轻弹”到另一侧,以更改页面。在“轻弹”过程中,如果文本框要更新,它会将主页跳回 View 。
在没有视频的情况下,很难用文字解释。但是想象一下按住鼠标左键并稍微拖动全景屏幕 - 例如,查看下一页但尚未翻转。好吧,如果文本框要在这段时间内更新,您将松开鼠标单击,它会跳回主页面。
一旦你进入下一页,它就会停留,我可以看到上一页的溢出更新。那里没什么大不了的。但它只是试图进入下一页。
我是 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 bool 值。并将其传递给事件等。
关于windows-phone-7 - 为什么WP7全景页面更新时会跳回去?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4029021/