Home > Silverlight > How to Create Global Resources

How to Create Global Resources


At times we may have to create resources or variable which stays till application variables. We call those variable as Global Variable.How can we create and access those global variables in Silver light

Firstly,we need to add variable to Resource property of App.XAML.CS

this.Resources.Add(“Gloabal”, EMployeeID);


Application.Current.Resources.Add(“Gloabal”, EMployeeID);

Here EmployeeID is of Integer variable.

U can also set in XAML  <Application.Resources> tag

To read value from Application Resources, we may use Application.Current.Resources[“Global”];


There is also Second way of doing,

Step 1) Create a Public Property in APP.XAML.cs like below

public string EMPID

Step 2) Set the value in EMPID property

private void Application_Startup(object sender, StartupEventArgs e)

//Assuming EMPID is passed from Initparams or u can write ur own logic to get empID from session or DB.
var param = e.InitParams;
if (param.Keys.Contains(“EMPID”))
EMPID = param[“EMPID”];
this.RootVisual = new MainPage();


Step 3) To read the value across the current  silver light Application project.

App app = (App)App.Current;
string empID = app. EMPID;


Hope it is pretty straight forward



Categories: Silverlight
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: