How to transfer values ​​from one xaml page to another in Metro style app

I have two XAML pages: Menu.xaml and Main.xaml.

In Menu.xaml, I have two buttons (Easy and Hard), and when I click the buttons, I go to Main.xaml.

I want to pass some value when I click "Easy" or "Hard" so that I can fill Main.xaml accordingly.

1. How to pass values ​​/ arguments to C #?
2. Where can I get these values ​​(for example, on the Load page?)

+5
source share
2 answers

Take a look at the methods Frame.Navigate. There is an overload that allows you to pass a parameter.

Look at an example

This usually looks something like this:

private void OnButtonClick(object sender, EventArgs args)
{
    if (sender == easyButton)
      NavigateToDifficulty(DifficultyLevel.Easy);
    else
      NavigateToDifficulty(DifficultyLevel.Hard);
}

private void NavigateToDifficulty(DifficultyLevel difficulty)
{
   this.Frame.Navigate(typeof(DifficultyPage), difficulty)
}

, LayoutAwarePage ( ) LoadState method

+3

Metro .

# :

, .

this.Frame.Navigate(typeof(Main),myDifficulty); 

, , OnNavigatedTo.

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    var myDifficulty= e.Parameter; 
    ...    
} 
+2

All Articles