简体   繁体   中英

Wpf application variable not changing

In my application I need some variables on almost all the pages so I declared them in Application.xaml like

<sys:String x:key="First">First</sys:String>

and on one page I change the value in code like

Resources["First"] = "This is First";

on the second page when I call the variable like

String f = (string)this.TryFindResource("First");
MessageBox.Show(f);

the out put is "First" and not "This is First". I also tried like.

Application.Current.Properties["First"]

You need to use Binding for such scenarios.

If you want the value to be globally available, make it static and then access it like:

<TextBlock Text="{x:Static local:MyGlobalClass.First}" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM