Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pagekey becomes null in OnNavigatedFrom in layoutawarepage

I am developing a windows 8 app and I have the following page, a contact picker page where i have a submit button with the following code

 customContact = (CustomContacts)contactView.SelectedItem;   
 this.Frame.Navigate(typeof(AddTask), customContact);

my AddTask page has the follwoing method

 protected  override void OnNavigatedTo(NavigationEventArgs e)
    { if (e.Parameter == null)
        {code logic }}

now I m getting an error in layout aware page during button click as PageKey is null in its onnavigatedfrom event as such

  protected override void OnNavigatedFrom(NavigationEventArgs e)
    {                    
        var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
        var pageState = new Dictionary<String, Object>();
        this.SaveState(pageState);          
        frameState[_pageKey] = pageState;
    } 

Pls help me out

like image 489
wickjon Avatar asked May 22 '13 07:05

wickjon


1 Answers

_pageKey value is being set in LayoutAwarePage.OnNavigatedTo. Since you have overriden OnNavigatedTo in you own page without calling the base implementation, the code in LayoutAwarePage setting _pageKey never gets called.

When overriding a method you should always call its base implementation unless you know very well why you're not doing it. Adding the call to base.OnNavigatedTo(e) should fix your problem:

protected override void OnNavigatedTo(NavigationEventArgs e)
{ 
    base.OnNavigatedTo(e);
    if (e.Parameter == null)
    {
        // code logic 
    }
}
like image 84
Damir Arh Avatar answered Oct 29 '22 19:10

Damir Arh