我正在为一个简单的 WP7 应用程序设置墓碑。我有一个项目列表,我想将 ListBox.SelectedIndex 保存在状态内存中,并在返回页面时,在列表中选择该项目。
当我尝试以下代码时,保存该值似乎有效(我已通过在 MessageBox 中显示它来确认)但未选择列表项。
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if (State.ContainsKey("activeResult"))
{
listBox1.SelectedIndex = Convert.ToInt32(State["activeResult"]);
}
base.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
State["activeResult"] = listBox1.SelectedIndex;
base.OnNavigatedFrom(e);
}
代码编译没有错误 - 但列表框项目从未被选中。感谢您的帮助!干杯威尔