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

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();
        }

 

posted @ 2020-08-10 11:37  FredGrit  阅读(224)  评论(0编辑  收藏  举报