更改框架时出现ArgumentNullException [英] ArgumentNullException on changing frame

查看:79
本文介绍了更改框架时出现ArgumentNullException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图在Windows 8应用程序中更改框架.我尝试按照

So I'm trying to change frames in a windows 8 app. I tried following the tutorial at this page, but I keep getting the same error.

我在行上收到ArgumentNullException:

I'm getting an ArgumentNullException on the line:

frameState[_pageKey] = pageState;

LayoutAwarePage.cs类中的

,位于OnNavigatedFrom方法中.

in the LayoutAwarePage.cs class, in the OnNavigatedFrom method.

现在,我不确定为什么会出现此错误,因为我觉得没有什么可能导致此错误.我的按钮onclick函数具有以下代码:

Now I'm not sure why I get this error, because I feel that there is nothing that could cause it in my code. My button onclick function has this code:

DateTime chosenDateTime = new DateTime(year, month, day, hours, minutes, seconds);
this.Frame.Navigate(typeof(MainPage), chosenDateTime.ToString());

我的MainPage中的OnNavigatedTo方法看起来像这样:

And the OnNavigatedTo method in my MainPage looks like this:

protected override void OnNavigatedTo(NavigationEventArgs e) {
   string parameter = (string)e.Parameter;
   if (parameter != "") {
       Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
       roamingSettings.Values["chosenDateTime"] = parameter;
       chosenDateTime = Convert.ToDateTime(e.Parameter);
   } else {
       Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
       if (roamingSettings.Values.ContainsKey("chosenDateTime")) {
           chosenDateTime = Convert.ToDateTime(roamingSettings.Values["chosenDateTime"].ToString());
       }
       if (roamingSettings.Values.ContainsKey("headline")) {
           chosenDateTextBlock.Text = roamingSettings.Values["headline"].ToString();
       }
   }
   SetTime();
}

任何人都可以给我一些有关如何解决此问题的信息吗?

Can anyone give me some information as to how I can solve this?

谢谢.

推荐答案

好的,所以我找到了自己的问题的答案!

Alright, so I found the answer to my own question!

在我所指的两个页面上,我都必须至少实现了这两种方法的最小实现:

On both pages I refer to and from I had to have implemented at least the minimal implementation of the 2 methods:

protected override void OnNavigatedTo(NavigationEventArgs e) {
    base.OnNavigatedTo(e);
}

protected override void OnNavigatedFrom(NavigationEventArgs e) {
    base.OnNavigatedFrom(e);
}

还有

base.OnNavigatedFrom(e);
base.OnNavigatedTo(e);

在方法中具有非常重要的意义.

were very important to have in the methods.

这篇关于更改框架时出现ArgumentNullException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆