如何在主应用程序窗口之后直接打开窗口
我的应用程序的主 UI 位于 MainWindow.xaml 中。
首先 - 是什么导致该窗口成为应用程序在启动时打开的窗口。它似乎没有被定义为“启动对象”,并且似乎没有任何专门启动此窗口的代码。
我可以在应用程序启动时在 MainWindow.xaml 的加载事件中显示登录窗口,定义一个新的“login.xaml”并告诉它显示为对话框。但是,如果我这样做,则在登录关闭之前不会出现主窗口。
我想要实现的是,当我的应用程序启动时,出现主窗口,然后在其顶部以模式方式显示登录窗口。
这怎么能做到呢?
My app's main UI is in MainWindow.xaml.
Firstly - what is causing this to be the window the application opens on startup. It does not appear to be defined as a "starup object" and there does not appear to be any code that specifically launches this window.
I can make my login window appear when the app starts by in the loaded event of MainWindow.xaml defining a new "login.xaml" and telling it to show as a dialog. However, if I do this then MainWindow does not appear until Login has been closed.
What I want to achieve is when my app starts, the MainWindow appears and then on top of that the Login window is displayed modally.
How can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在VS中创建项目时,默认在
App.xaml
中定义了MainWindow
的启动:<前><代码><应用程序...
StartupUri =“MainWindow.xaml”>
<应用程序.资源>
在
Loaded
事件应该起作用,只是不要在尚未加载的构造函数中执行此操作。The startup of the
MainWindow
is defined inApp.xaml
by default when creating a project in VS:Creating the dialogue in the
Loaded
event should work, just don't do it in the constructor where it is not yet loaded.一种方法可能是将
Loaded
事件处理程序添加到主窗口,并在其中显示登录窗口:One way could be to add a
Loaded
event handler to your main window and in that display the login window:在 app.xaml 中,以下行定义启动窗口,您可以根据需要更改它
如果您遵循 MVVM,则可以使用 System.Windows 将命令绑定到 Windows 加载事件。交互性(否则只需按照其他人的建议创建一个事件处理程序)
In app.xaml the following line defines the startup window, you can change it if you want
If you are following MVVM you can bind a command to the windows loaded event using System.Windows.Interactivity (otherwise simply create an event handler as the others have suggested)