Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArgumentNullException on changing frame

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.

I'm getting an ArgumentNullException on the line:

frameState[_pageKey] = pageState;

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

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

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?

Thanks.

like image 596
Loyalar Avatar asked Dec 09 '12 18:12

Loyalar


1 Answers

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

And the

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

were very important to have in the methods.

like image 197
Loyalar Avatar answered Oct 21 '22 12:10

Loyalar