如何关闭窗口但仍使应用程序处于活动状态? [英] How to close a window but still have app current active?
问题描述
假设我有 2 个窗口:InputWindow 和 DisplayWindow
suppose i have 2 windows: InputWindow and DisplayWindow
当前:我想使用 InputWindow 通过 App 变量保存数据
Currently:i want to use InputWindow to hold data via an App variable
// in InputWindow
(App.Current as App).u_id = obj.id;
其中 u_id 是我在 app.xaml.cs 中定义的对象,obj.id 是 InputWindow 中的输入变量.
where u_id is the object i defined in app.xaml.cs and obj.id is the input variable in InputWindow.
但是,当我关闭 InputWindow 并显示 DisplayWindow 时:
However when i close InputWindow and display DisplayWindow:
// in InputWindow
DisplayWindow window = new DisplayWindow();
window.Show();
Application.Current.MainWindow.Close();
该应用程序还会杀死 InputWindow 中的数据.
The app also kill the data in the InputWindow.
所以我的问题是:
有没有办法将数据从关闭的窗口保存到打开的窗口?
Is there a way to keep the data via from the closed Window to the open Window?
推荐答案
Application.Current.MainWindow.Hide();
您可以使用此行隐藏窗口...或者您可以使用构造函数将要使用的信息传递到新窗口中.
You can hide the window using this line... or you can pass the information that you want to use into the new window using the constructor.
DisplayWindow window = new DisplayWindow(object myObject);
那个构造函数必须有你想要传递的信息,但这也可以解决问题.
That constructor must have the information you want passed but this can solve the issue as well.
这篇关于如何关闭窗口但仍使应用程序处于活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!