Create and access global variables in Windows 8 C# Metro app

If you would like to use a global variable in your WinRT C# app, one of the ways to do that is below.

Declare a global public variable and a static context of your current app in App.xaml.cs, in the C# code below from Metro RSS Reader I have declared the ARGB color that I want to use across all Frames in the app.

   1: public static Color ARGBColor = Color.FromArgb(255, 145, 0, 145);

   2: public static new App Current

   3: {

   4:     get { return Application.Current as App; }

   5: }

I can then use the above from the OnNavigatedTo event in any Frame like this

   1: protected override void OnNavigatedTo(NavigationEventArgs e)

   2: {

   3:       MainGrid.Background = new SolidColorBrush(App.ARGBColor);

   4: }