2012-04-08 29 views
0

在我的應用程序需要的幾乎所有的頁面的某些變量的WPF應用程序變量,所以我宣佈他們在Application.xaml像不改變

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

,並在一個頁面上我改變的值這樣的代碼

Resources["First"] = "This is First"; 
當我打電話像

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

的出來說就是「第一」和n變量在第二頁上

ot「這是第一」。我也嘗試過。

Application.Current.Properties["First"] 
+0

的可能的複製[http://stackoverflow.com/questions/910421/how-can-i -save-global-application-variables-in-wpf](http://stackoverflow.com/questions/910421/how-can-i-save-global-application-variables-in-wpf) – 2012-04-08 13:33:35

回答

1

您需要對這些方案使用Binding。

如果你想要的值是全局可用,使其靜態,然後訪問它像:

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

如何做到這一點碼? – 2012-04-08 15:17:27