如何在Metro风格应用程序中将值从一个xaml页面传递到另一个页面

nv.*_*now 6 c# xaml microsoft-metro windows-8 winrt-xaml

我有两个XAML页面:Menu.xaml和Main.xaml.

在Menu.xaml上,我有2个按钮(Easy&Hard),当我点击按钮时,我导航到Main.xaml.

当我点击'Easy'或'Hard'时,我希望传递一些值,以便我可以适当地填充Main.xaml.

1.如何在C#中传递值/参数?
2.我在哪里检索这些值(例如在PageLoad上?)

cor*_*erm 3

看看Frame.Navigate方法吧。有一个重载可以让您传入参数。

请参阅此示例

通常这看起来像这样:

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)
}
Run Code Online (Sandbox Code Playgroud)

要检索导航参数,请查看LayoutAwarePage(包含在示例模板中)LoadState方法