Pra*_*h R 5 c# windows-8 windows-runtime
我正在开发一个Windows 8应用程序,我有以下页面,一个联系人选择页面,我有一个提交按钮,代码如下
customContact = (CustomContacts)contactView.SelectedItem;
this.Frame.Navigate(typeof(AddTask), customContact);
Run Code Online (Sandbox Code Playgroud)
我的AddTask页面有以下方法
protected override void OnNavigatedTo(NavigationEventArgs e)
{ if (e.Parameter == null)
{code logic }}
Run Code Online (Sandbox Code Playgroud)
现在我在按钮点击期间在布局感知页面中出现错误,因为PageKey在其onnavigatedfrom事件中为null
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
var pageState = new Dictionary<String, Object>();
this.SaveState(pageState);
frameState[_pageKey] = pageState;
}
Run Code Online (Sandbox Code Playgroud)
请帮助我
_pageKey价值正在设定中LayoutAwarePage.OnNavigatedTo.由于您已经OnNavigatedTo在自己的页面中覆盖而没有调用基本实现,因此LayoutAwarePage设置中的代码_pageKey永远不会被调用.
覆盖方法时,除非您非常清楚为什么不这样做,否则应始终调用其基本实现.添加呼叫base.OnNavigatedTo(e)应解决您的问题:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.Parameter == null)
{
// code logic
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1092 次 |
| 最近记录: |