Windows store apps C#应用程序是否可以访问其他类的变量?

Windows store apps C#应用程序是否可以访问其他类的变量?,windows-store-apps,Windows Store Apps,如何从MainPage.cs中的变量(如“public static int intHallo=5;”)访问另一类应用程序(如BlankPage2.cs)中的变量?静电不起作用 来自汉诺威的问候 Christian如果需要全局变量,请在App.Xaml.cs中定义这些变量 public static int IntHallo = 5 public static new App Current { get { return Application.Current as A

如何从MainPage.cs中的变量(如“public static int intHallo=5;”)访问另一类应用程序(如BlankPage2.cs)中的变量?静电不起作用

来自汉诺威的问候
Christian

如果需要全局变量,请在App.Xaml.cs中定义这些变量

public static int IntHallo = 5

public static new App Current
    {
        get { return Application.Current as App; }
    }
然后您可以在OnNavigated to上使用它

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        Test.Text  = App.IntHallo;
    }
如果要在XAML页面之间传递参数,请执行以下操作:

//MainPage.cs:public类show{int intZahl=5;}私有无效按钮{u单击(对象发送方,RoutedEventArgs e){show intZahl=new show();this.Frame.Navigate(typeof(Page2),intZahl);}//Page2.cs:protected override void onnavigationEventargs e{navigationHelper.OnNavigatedTo(e);MainPage.show intZahl=(MainPage.show)e.Parameter;Test.Text=intZahl.ToString();}`intZahl始终为空?