-1

How can I access from a variable in MainPage.cs like "public static int intHallo = 5;" in another class of an App like BlankPage2.cs? Static does not work?

Greetings from Hannover Christian

  • // MainPage.cs: public class show { int intZahl = 5; } private void Button_Click(object sender, RoutedEventArgs e) { show intZahl = new show(); this.Frame.Navigate(typeof(Page2), intZahl); } // Page2.cs: protected override void OnNavigatedTo(NavigationEventArgs e) { navigationHelper.OnNavigatedTo(e); MainPage.show intZahl = (MainPage.show)e.Parameter; Test.Text = intZahl.ToString(); }` intZahl is always null? – user3447311 Mar 22 '14 at 20:52

1 Answers1

0

If you want a global variable, define these in App.Xaml.cs

public static int IntHallo = 5

public static new App Current
    {
        get { return Application.Current as App; }
    }

Then you can use it on the OnNavigated to.

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        Test.Text  = App.IntHallo;
    }

If you want to pass parameters between XAML pages, follow this: How to pass values (parameters) between XAML pages?

Community
  • 1
  • 1
TechnoTim
  • 3,065
  • 1
  • 23
  • 28