WP7 Development App / Page wide variable

Does anyone know how to set a variable that can be accessed on all pages of a Windows Phone 7 application?

+5
source share
3 answers

Without knowing any specific features of your situation, you can create variables as members of your App class:

  public partial class App : Application
  {
    ...
    public int foo { get; set; }
    ...
  }

Then select if from:

  (App.Current as App).foo = 3;
+14
source

Set global variables, quick and easy, create a new class for GlobalVariables:

public static class GlobalVariables
{
   public static string my_string = "";
   public static int my_int = -1;
}

Then you access the global variable class as follows:

GlobalVariables.variable_name;
+3
source

, , - :

    Dictionary<string, int> clients;//Global variable

    // Constructor
    public MainPage()
    {
        InitializeComponent();
        clients = new Dictionary<string, int>();
    }
0

All Articles