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

1.New Wpf project;spa

2.Add New Wpf Window named SubWindow;code

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

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

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

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

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

private void Button_Click(object sender, RoutedEventArgs e)
        {
            SubWindow subWin = new SubWindow();
            subWin.Show();
        }
相關文章
相關標籤/搜索