1

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?

Mangesh
  • 5,491
  • 5
  • 48
  • 71
Judy
  • 424
  • 2
  • 4
  • 13
  • Just a guess but your variable names "Content" and maybe "Combobox" might interfere with built in types. Try to rename these two variables. – Hyndrix Feb 25 '15 at 16:47
  • Is it an universal app, or a Silverlight app? – Kevin Gosse Feb 25 '15 at 17:00
  • The compiler seems to be trying to access the type `NavigationContext` instead of the property defined in your page (by inheritance from `PhoneApplicationPage`), but I have trouble understanding why. You should try using the `this` keyword and see if you get a more explicit error message: `this.NavigationContext.QueryString.TryGetValue("param1", out Combobox);` – Kevin Gosse Feb 25 '15 at 17:05
  • I tried this way ,and i have this error : Error 1 'FastHealing.ShowParams' does not contain a definition for 'NavigationContext' and no extension method 'NavigationContext' accepting a first argument of type 'FastHealing.ShowParams' could be found (are you missing a using directive or an assembly reference?) – Judy Feb 25 '15 at 17:10
  • Don't initialize the strings to `""`. As you are passing them as `out` parameter, only declare them. – Mangesh Feb 25 '15 at 17:47
  • So there's definitely something wrong with your class... Can you copy/paste the class definition? – Kevin Gosse Feb 25 '15 at 21:00
  • I tested this code on device & its working fine. No exception, nothing! I suggest you to give different variable names, clean the solution & rebuild. Try testing on device. – Mangesh Feb 26 '15 at 05:39
  • Thanks ... I solved this .. just replaced NavigationContext with Frame.Navigate . – Judy Feb 26 '15 at 06:43
  • Then it means you're using WinRT, not Silverlight ;) – Kevin Gosse Feb 26 '15 at 06:58

2 Answers2

2

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.

0
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>;
}
Abdullah El-Menawy
  • 388
  • 1
  • 5
  • 17