Wpf change application variable

Go To StackoverFlow.com

0

I want to declare some application level variables. These variables changes with values on different pages. I declare a variable like this

<sys:String x:key="Item1">Test</sys:String>

Now in my code I want to change it so the code should be

Application.Current.Properties["Item1"] = "This is a test";
String t = (string)this.TryFindResource("Item1");
MessegeBox.Show(t);

but this code is not changing the value and it always gives "Test" Any Idea how to fix that.

2012-04-04 19:29
by Hasan Zubairi


0

Application properties are unrelated to XAML resources. Do this:

    Resources["Item1"] = "This is a test";
    String t = (string)this.TryFindResource("Item1");
    MessageBox.Show(t);

But really what you should probably be doing instead here is the MVVM pattern (google it)

2012-04-04 19:39
by Robert Levy
Ads