WPF call global variable via App.Current.Properties[ObjKey]=ObjValue

  • A+
所属分类:.NET技术
摘要

1.New Wpf project;2.Add New Wpf Window named SubWindow;3.Set global vairable via App.Current.Properties[objKey]=objValue in MainWindow constructor.

1.New Wpf project;

2.Add New Wpf Window named SubWindow;

3.Set global vairable via App.Current.Properties[objKey]=objValue in MainWindow constructor.

 public MainWindow()         {             InitializeComponent();             App.Current.Properties["CurrentId"] = "FB8EA0F0-CC46-4A7F-8E95-697B04F543D1";          }

4.Invoke and call the assigned global variable in sub window constructor 

public SubWindow()         {             InitializeComponent();             MessageBox.Show(App.Current.Properties["CurrentId"].ToString());         }

5.In the MainWindow page,click the button and show the result.

private void Button_Click(object sender, RoutedEventArgs e)         {             SubWindow subWin = new SubWindow();             subWin.Show();         }