Wpf MainWindow封装多个窗口-让StartupUri显示多个窗口
目的是创建一个包含多个 WPF 窗口的对象,该对象代表一个应始终一起显示的单元,每个 Window
保留其各自的职责 - 比如说选择布局在screen X ...
现在因为 WPF 是单窗口架构,我想将这个 Windows 列表包装在单个 Window
对象中,以便可以设置它例如,作为 StartupUri。
- 我知道我可以在
Application
启动中手动Show()
每个Window
,但这不是重点 - 我需要一组粘着的窗口在一起,我可以轻松地在代码库中的任何地方调用它们,因为我知道我有一个类来处理链接。 - 对这里的多文档接口 MDI 不感兴趣,
我不知道如何实现这样的适配器,我尝试重写 BeginInit
,但根本没有被调用。
如何停止窗口初始化
public class MultiWindow : Window
{
private readonly IList<Window> _windows = new List<Window>();
public void Register(Window window)
{
_windows.Add(window);
}
public override void BeginInit()
{
foreach (var w in _windows)
w.Show();
// base.BeginInit();
}
}
我不太了解Window
生命周期,有什么办法可以取消初始化并显示已注册窗口的列表吗?
The aim is to create an object that contains a number of WPF windows, which would represent a unit that should always be shown together, each Window
retaining its own individual responsibilities - say choosing to be laid out on a screen X ...
Now because WPF is a single-window architecture, I would like to wrap this list of Windows in a single Window
object, so that it could be set as StartupUri, for instance.
- I know I could manually
Show()
eachWindow
inApplication
startup, but that is not the point - I need a collection of windows that stick together and which I can easily call upon anywhere in my codebase, knowing I have one class that has taken care of the linkage. - Not interested in Multiple Document Interface MDI here
I do not know how to implement such an adapter, I tried to override BeginInit
, but that did not get called at all.
How to stop Window initialization
public class MultiWindow : Window
{
private readonly IList<Window> _windows = new List<Window>();
public void Register(Window window)
{
_windows.Add(window);
}
public override void BeginInit()
{
foreach (var w in _windows)
w.Show();
// base.BeginInit();
}
}
I do not understand Window
lifecycle much, is there anyhow I could cancel the initialization and show the list of registered windows instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信startupuri将允许您在应用程序启动时打开一个窗口
如果您想在应用程序启动时打开窗口,可以这样做。
有App.xaml文件,请转到App.xaml.cs文件。
请尝试...按照
App类继承自Application。您可以重写 OnStartup() 来自定义应用程序启动时间。
我不确定这是否是您想要的。我希望这有帮助。
I believe that the startupuri will allow you to open a windows when the application start up
If you want to open windows when the application start up, you can do this way.
There is App.xaml file, please go to App.xaml.cs file.
please try...following
App class inherited from Application. You can override OnStartup() to customize application stating up time.
I am not sure that this is what you want. I hope this help.
我找到了一种方法来做到这一点,即为普通的单个
Window
对象和实际上的Window
对象创建所有窗口的子类BaseWindow
包含多个窗口。.Show()
时,它将显示一个或多个窗口,具体取决于子类中封装的内容。所有 Window 对象都应继承自 BaseWindow
重写 BaseShow()
在应用程序启动时设置 MultiWindow
使用 MultiWindow,但通过 BaseWindow 调用重写成员
PS 我希望 Microsoft 在整个 .NET 中使用接口,使用 IWindow 接口而不是具体的 Window 类提供更多的功能,在这种情况下,也易于实施。
I found a way to do it, which is by making all my windows subclass
BaseWindow
, for both normal singleWindow
objects and forWindow
objects actually containing multiple windows..Show()
it will either show one window or multiple, depending on what is encapsulated in the subclass.All Window objects should inherit from BaseWindow
Override BaseShow()
Set up MultiWindow in application startup
Use MultiWindow, but call overriden members through BaseWindow
P.S. I wish Microsoft employed interfaces throughout .NET, working with IWindow interface rather than the concrete Window class would provide much more power and in this case, also ease-of-implementation.