ProblemYou have an application with more than one page. And you want to send values from one page to another.
Solution
Sometimes you need global variables that can store current user activities and such. The best thing to store and display a global value is doing it the "Querystring Way". Web Developers surely understand what I'm talking about. You can set external variables when you write navigation code:
private void button1_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate(new Uri("/Page2.xaml?ID=1", UriKind.Relative)); }
Just like in the web!
When we navigated to Page2.xaml, we must also display them, right?
This simple code will display the value in a TextBlock control:
string var; if(NavigationContext.QueryString.TryGetValue("ID",out var)) { textBlock1.Text = var; } Now let's see the results:
string var; if(NavigationContext.QueryString.TryGetValue("ID",out var)) { textBlock1.Text = var; }
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: