2

I am trying to work out how to transfer string value from one windows phone app page to the next, following this article but I get an error that reads "The name 'NavigationService' does not exist in the current context".

There is a textbox and a button on page1. There is only a TEXTBLOCK on page 2. I wish to enter a string in the textbox of page 1, and when the button is clicked, the page 2 shows up with the text from the textbox (of page 1) in the textblock of page 2.

For the button click even in page 1, I entered this:

private void Button_Click(object sender, RoutedEventArgs e)
{

    NavigationService.Navigate(new Uri("/Page2.xaml?msg=" + Texbox_page1.Text, UriKind.Relative));

}

In the OnNavigatedTo method, in page 2, I entered

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    string msg = "";

    if (NavigationContext.QueryString.TryGetValue("msg", out msg))
    {
        Textblock_nickname_display.Text = msg;
    }
}

What am I missing? If there is n easier way to do this, please share!

I've spend almost 4 hours trying to figure this out, watching YouTube videos and what not!

Thanks in advance!

Rich Turner
  • 9,986
  • 1
  • 47
  • 64
Anonymous Person
  • 1,217
  • 6
  • 21
  • 42
  • 1
    And I get "The name 'NavigationContext' does not exist in the current context" on the OnNavigatedTo page (page 2).. – Anonymous Person Mar 11 '15 at 21:22
  • What type of Windows Phone app are you creating? WinPhone7? WinPhone 8? WinPhone 8 Silverlight? WinPhone 8.x Universal/Store? – Rich Turner Mar 11 '15 at 21:50
  • The project is Universal App, but I am doing all the stuffs for just the Windows Phone 8.1 using Windows Runtime – Anonymous Person Mar 11 '15 at 22:05
  • possible duplicate of [Windows Phone 8.1 - Page Navigation](http://stackoverflow.com/questions/23154359/windows-phone-8-1-page-navigation) – Igor Ralic Mar 12 '15 at 11:04

2 Answers2

1

Make sure you have

using System.Windows.Navigation;

Also, make sure your pages inherit from the proper base class.

public class SecondPage : PhoneApplicationPage
{

...

}

EDIT: Right click your project in the solution explorer and click Add > Reference and search for PresentationFramework. Adding that reference should give you the namespace you need.

mambrow
  • 430
  • 5
  • 13
  • Hi, thats the problem.. It throws an this error: The type or namespace name 'Navigation' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) – Anonymous Person Mar 11 '15 at 21:39
  • /that is when i add "using System.Windows.Navigation;" – Anonymous Person Mar 11 '15 at 21:40
  • I also tried this on page 2 public Page2(string str_Value) //overloading the constuctor { this.InitializeComponent(); Textblock_nickname_display.Text = str_Value; } then on the button click event of page 1, this is what i put private void Button_Click(object sender, RoutedEventArgs e) { Page2 page2 new Page2(Texbox_nickname_extraction.Text); } – Anonymous Person Mar 11 '15 at 21:51
  • 1
    Manage to fix it following this: http://stackoverflow.com/questions/20884096/how-to-get-the-text-of-textbox-to-textblock-in-another-xaml-c-sharp-windows-sto But thnx for looking though :) – Anonymous Person Mar 11 '15 at 23:00
0

Your project is Windows Phone 8.1 (Universal), So NavigationService isn't exist any longer.

You can use Frame.Navigate method in WP 8.1.

And below is my answer about Page Navigation in Windows Phone 8.1, please read it:

Windows Phone 8.1 - Page Navigation

Community
  • 1
  • 1
Chris Shao
  • 7,991
  • 3
  • 36
  • 37