Error while getting data from NavigationContext

360 Views Asked by At

I am creating a Reminder app using C# in Visual Studio 2013. One of the pages is for launching the notification.

My code is :

protected override void OnNavigatedTo(NavigationEventArgs e)
    {

       base.OnNavigatedTo(e);

       string Combobox = "";
       string Content = "";

     NavigationContext.QueryString.TryGetValue("param1", out Combobox);

     NavigationContext.QueryString.TryGetValue("param2", out Content);

     param1TextBlock.Text = Combobox;
     param2TextBlock.Text = Content;     

    }

But the errors occur in this part :

     NavigationContext.QueryString.TryGetValue("param1", out Combobox);

     NavigationContext.QueryString.TryGetValue("param2", out Content);

The Error is :

Error 1 An object reference is required for the non-static field, method, or property 'System.Windows.Navigation.NavigationContext.QueryString.get'

Any idea?

2

There are 2 best solutions below

1
Abdullah El-Menawy On BEST ANSWER
List<string> MyStringsList = new List<string>();

this.Frame.Navigate(typeof(PageName),MyStringsList);

this code is used for navigation with parameters, you can get these parameters at the navigated to page in OnNavigatedTo event :

protected override void OnNavigatedTo(NavigationEventArgs e)
{

   List<string> MyRecievedParameters = e.Parameter as List<string>;
}
0
Sergey Parshin On

Most likely you have created "Windows Phone" application project, while you need to create "Windows Phone Silverlight" to be able to access the NavigationContext class.