Navigating and Passing Data between XAML Pages - Day 3 - Part 3

Download this episode

Download Video

Description

Most applications—even simple ones—will require at least two or more Silverlight pages. This video demonstrates how to navigate from one Silverlight page to another, as well as how to pass information between two pages using QueryStrings. Finally, Bob explains how to use the phoneAppService.State[] to save important values in case the user wants to navigate back to a page and expects to see the data and control property settings as they were previously set.

Download the source code in c#

Download the source code in VB.Net

Embed

Format

Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image
      Sven

      /appname;component/foldername/pagename doesn't work for me to navigate between pages.
      What does work is simply /pagename (or /foldername/pagename for that matter). Perhaps they have updated that since you produced the vid..? (wouldn't be surprised if they did that in response to developers having a hard time with that unintuitive "/appname;component/" way with no assistance from VS whatsoever)

    • User profile image
      Clint

      @Sven: You actually don't have to do it that way.  There is a much easier way. For this example if you just had your NavigateUri="/View/Page1.xaml" you'd be fine.  This also would work if you did NavigateService.

      NavigationService.Navigate(new Uri("/Views/Page1.xaml", UriKind.Relative));

    • User profile image
      jamesoneill

      it is COLON not SEMI colon in the path. The video was just clear enough to see that although bob says semi colon it might be a colon and after an hour of messaging about thinking I had the terms in the path wrong, I tried /appname:folder/filename.xaml and it worked.

       

    • User profile image
      send2sev

      Hi there

      I just wanted to ask if "AppPhoneService.State["value"]" is the way to keep values like Sessions in asp.net or no. Is there anything else like Sessions here?

    • User profile image
      Brendan

      Like Sven the "/NavigatingBetweenP..." does not work (using VS2010 VB .NET) but simply "/folder/file" does work.

    • User profile image
      Mintydog

      I tried mine with colon : and it didnt work, then with semi colon ; and it didnt work. then all I did was changed the p in page1.xaml to a capital and it worked, then when I went back to the URI it was in lower case and it still worked. very strange. But cool video anyway

    • User profile image
      Jaguma
      Brilliant. Thanks for this. I have been following your tutorials since the first one. They have been the BEST tutorials for any programming language I have found :)
    • User profile image
      made_rdj

      I have a question related to the final part of this tutorial where Bob overrode the navigate to/from methods. He did this in order to ensure that previous input was stored and displayed correctly after navigating back through the hyperlink button. He stated that he needed to do this as the hyperlink button caused a new instance of the mainpage to be created.

      I am presuming that overriding the methods does not prevent the creation of a new main page instance but simply populates the new instance with the correct data.

      Does this mean that the application will now have 2 instances of main page loaded in memory? If yes, How do you ensure that your navigation from a hyperlink returns to the already instantiated page?

      You could possibly create an application with many means of navigating to a given page. Having multiple instance of the same page loaded into memory seems rather wasteful.

    • User profile image
      Sewoldt

      @made_rdj Those were so interesting questions. I tried to guess some answers. I think that when you navigate away from a page, that instance of the page is always destroyed. It seems logical because the page is no longer shown, and when you navigate again into the page, another instance of the page is created, so, there is always only one instance of that page. When you navigate back to the page by using the back button, a new instance of the page is created, but is populated with data that Silverlight stored somewhere. I guess you're always getting a fresh instance of the page (populated with data or no depending on whether you are using the back button or a hyperlink) and there are no unreachable multiple instances of the page wasting the memory.

    • User profile image
      YanivC

      Wondering why he went his route with vb.net when this works fine:
      Dim str as String = String.Empty
      NavigationContext.QueryString.TryGetValue("language", str)

    • User profile image
      Mr_Smitty0

      Quick question if I may. When using the "NavigationService" class there is a method called... GoBack(). Is there a reason it was not covered in this video? Say... maybe can present some unwanted issues? Or is it just one of those "Well here is another way to achieve the same result"?

      private void button1_Click(object sender, RoutedEventArgs e)
              {
                  NavigationService.GoBack();
              }

      Great videos guys!!!

    • User profile image
      Jeni

      I have a question related to this video.
      Should we use only hyperlink button to navigate between the pages?
      cant we use button control? suppose if i want to go to next page after i click on the button,how can i do that? can anyone plsss tell me...

    • User profile image
      Adi4champ

      @Jeni.
      u can use button in place of hyperlink.Code is like that:-

       NavigationService.Navigate(new Uri("/AppName;component/Page.xaml", UriKind.Relative));

    • User profile image
      Nishant

      If I may ask then have a look at this article which has defined all the techniques with samples to pass data among pages in WP7.

      http://nishantcop.blogspot.com/2011/08/passing-data-between-pages-in-windows.html

      Rgds
      Nishant

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.