Windows Phone 7 - Transferring Values ​​Between Pages

I am trying to send values ​​between pages using:

NavigationService.Navigate(new Uri("/ABC.xaml?name=" + Company + "&city=" + City , UriKind.Relative)); 

Here, the values ​​of the Company and the city are transferred to the next page, because company names such as "ABC and Ltd" do not work properly, they simply transfer "ABC" to the next page. Basically, the part after & is discarded.

Is there an option to format this? Or should I write logic for this ??

Do you need help!

thanks

+6
source share
3 answers

If any of your query strings contains characters that are considered invalid in Uri, then what you do will fail, as you have discovered. You must use Uri.EscapeDataString to avoid any illegal characters first. Change the code you posted to the following:

 NavigationService.Navigate( new Uri( String.Format( "/ABC.xaml?name={0}&city={1}", Uri.EscapeDataString( Company ), Uri.EscapeDataString( City ) ), UriKind.Relative ) ); 

Captured lines are not automatically displayed when reading them using NavigationContext.QueryString , so there is no need to explicitly call Uri.UnescapeDataString .

+6
source

The & character is treated as a special character in query strings as a means of separating values. It must be escaped in %26 .

For more information on how to easily remove URLs using Uri.EscapeUriString .

For instance:

 string Company = "ABC & D"; string City = "Falls Church"; string escaped = Uri.EscapeUriString("/ABC.xaml?name=" + Company + "&city=" + City); var uri = new Uri(escaped, UriKind.Relative); 
+2
source

You can also pass you the App.xaml.cs code, where you can define the global values ​​that you can get throughout your application,

http://www.developer.nokia.com/Blogs/Community/2011/08/25/passing-data-between-pages-in-windows-phone-7/

0
source

Source: https://habr.com/ru/post/895902/


All Articles