在windows phone7透视控件模板项目中,如果您从特定透视表项转到搜索页并在手机上选择后退,则透视控件页不会记住所选的项。它总是返回到透视控件的第一项。
如何更改此行为?这样,如果您在第3个轴心项上,然后转到搜索并返回,则会返回到第3个轴心项。
Pratik
发布于 2010-11-19 11:28:02
当你按下搜索按钮时,你的应用程序就会被删除(换句话说,应用程序会被停止并尽可能长时间地保存在内存中),.It完全取决于你(开发人员)如何处理它。系统本身只做几件事来获取最后的状态-比如导航到最后一页。你可以把它想象成浏览器中的cookies。如果您按下后退按钮,浏览器将检查是否存在cookie,并从cookie中加载内容。
有几种方法可以处理它,并为用户提供最佳的用户体验。可以将状态保存到状态集合或直接保存到IsolatedStorage。在App.xaml.cs中使用事件
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
}或带有枢轴的页面的事件
// set state
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
#if DEBUG
Debug.WriteLine("TOMBSTONING EVENT: OnNavigatedFrom at {0}", DateTime.Now.ToLongTimeString());
#endif
//try to locate state if exists
if (State.ContainsKey(App.STATE_KEY))
{
//clear prev value
State.Remove(App.STATE_KEY);
}
State.Add(App.STATE_KEY, this.State);
base.OnNavigatedFrom(e);
}
// get state
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// try to locate the state from previous run
if (State.ContainsKey(App.STATE_KEY))
{
// return previous state
var s = State[App.STATE_KEY] as Info;
if (s != null)
{
#if DEBUG
Debug.WriteLine("TOMBSTONING EVENT: OnNavigatedTo at {0}", DateTime.Now.ToLongTimeString());
#endif
this.State = s;
}
}
base.OnNavigatedTo(e);
}将此模式用于具有透视的页面,并保存透视控件的最后一个索引。try和catch块也很好。
Overview Lifecycle <-一部电影
https://stackoverflow.com/questions/4221615
复制相似问题