Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 App?

like image 711
Al3xhamilton Avatar asked Jun 19 '11 23:06

Al3xhamilton


2 Answers

Without knowing any more specifics of your situation, you could create the variables as members of your App class:

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

Then access if from wherever:

  (App.Current as App).foo = 3;
like image 200
i_am_jorf Avatar answered Nov 13 '22 00:11

i_am_jorf


Setup global variables, quick and easy, make 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 Variables class like this:

GlobalVariables.variable_name;
like image 25
jihchuan Avatar answered Nov 13 '22 02:11

jihchuan