Passing values between XAML pages

后端 未结 1 564
旧巷少年郎
旧巷少年郎 2021-01-25 00:23

I\'m trying to build my first Windows 8 Metro App using VS 2012 & C#.

It consists of a simple 2 pages layout, the first being the presentation & setup page and t

相关标签:
1条回答
  • 2021-01-25 00:33

    You can pass parameter object in Frame's Navigate(...) method. So you should write like this.

    MainPage.xaml.cs

    Player p = new Player();
    this.Frame.Navigate(typeof(MainGame), p);
    

    Now that object of Player can be get in MainGame.xaml.cs's OnNavigatedTo(...) method.

    MainGame.xaml.cs

    protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
        var objPlayer = e.Parameter as Player; 
    }
    
    0 讨论(0)
提交回复
热议问题