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
_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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With