c# - 更改框架时出现 ArgumentNullException

标签 c# windows-8 argumentnullexception page-state

所以我正在尝试更改 Windows 8 应用程序中的框架。我尝试按照 this page 上的教程进行操作,但我不断收到同样的错误。

我在线上收到 ArgumentNullException:

frameState[_pageKey] = pageState;

在 LayoutAwarePage.cs 类中的 OnNavigatedFrom 方法中。

现在我不确定为什么会出现这个错误,因为我觉得在我的代码中没有任何东西可以导致它。我的按钮 onclick 函数具有以下代码:

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

我的 MainPage 中的 OnNavigatedTo 方法如下所示:

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();
}

谁能给我一些关于如何解决这个问题的信息?

谢谢。

最佳答案

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

在我引用的两个页面上,我必须至少实现这两种方法的最小实现:

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

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

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

在方法中非常重要。

关于c# - 更改框架时出现 ArgumentNullException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13790344/

相关文章:

c# - Selenium C# 无法使用 FindElements 获取列表

c# - 使用属性和约定路由

c# - 映射不同类型对象的通用方法

windows - Windows 8 Store App 中的 XAML 对齐

java - 为什么空异常运行时错误出现在 line `outputFile.println("Package : "+ letter);` ?

c# - 有任何理由抛出 DivideByZeroException 吗?

c# - Windows Phone 8.1 应用程序中的本地设置未存储

javascript - touchmove/MSPointerMove 事件未在 Windows 8 中触发

javascript - Windows 8 JavaScript 项目中的 bld 和 bin 文件夹的用途是什么?

java - 使用 getSupportActionBar 时出现 NullPointerException