如何在主应用程序窗口之后直接打开窗口

发布于 2024-12-12 22:16:55 字数 288 浏览 0 评论 0原文

我的应用程序的主 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浪漫之都 2024-12-19 22:16:55
  1. 在VS中创建项目时,默认在App.xaml中定义了MainWindow的启动:

    <前><代码><应用程序...
    StartupUri =“MainWindow.xaml”>
    <应用程序.资源>


  2. Loaded 事件应该起作用,只是不要在尚未加载的构造函数中执行此操作。

    Loaded="Window_Loaded"
    
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        新的LoginDialogue().ShowDialog();
    }
    
  1. The startup of the MainWindow is defined in App.xaml by default when creating a project in VS:

    <Application ...
                 StartupUri="MainWindow.xaml">
        <Application.Resources>
    
        </Application.Resources>
    </Application>
    
  2. Creating the dialogue in the Loaded event should work, just don't do it in the constructor where it is not yet loaded.

    Loaded="Window_Loaded"
    
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        new LoginDialogue().ShowDialog();
    }
    
始于初秋 2024-12-19 22:16:55

一种方法可能是将 Loaded 事件处理程序添加到主窗口,并在其中显示登录窗口:

this.Loaded += LoadedEventHander;


void LoadedEventHander(object sender, RoutedEventArgs e)
{
    // Show Login.xaml here.
}

One way could be to add a Loaded event handler to your main window and in that display the login window:

this.Loaded += LoadedEventHander;


void LoadedEventHander(object sender, RoutedEventArgs e)
{
    // Show Login.xaml here.
}
浅语花开 2024-12-19 22:16:55
  1. 在 app.xaml 中,以下行定义启动窗口,您可以根据需要更改它

    StartupUri="MainWindowView.xaml"
    
  2. 如果您遵循 MVVM,则可以使用 System.Windows 将命令绑定到 Windows 加载事件。交互性(否则只需按照其他人的建议创建一个事件处理程序)

    
        
            
        
    
    
  1. In app.xaml the following line defines the startup window, you can change it if you want

    StartupUri="MainWindowView.xaml"
    
  2. 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)

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <i:InvokeCommandAction Command="{Binding MyICommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文