应用程序xaml假设实例化的第一个窗口是主窗口(忽略showdialog),我需要显示多个窗口

发布于 2024-10-03 01:03:18 字数 1356 浏览 6 评论 0原文

我的 App.xaml.cs 中有以下代码

private void App_Start(object sender, StartupEventArgs e)
{
  if ( CompletedInstall())
  {
    //using show to allow for pacifier if loading is slow
    var manager = new WINServiceConfig();
    MainWindow = manager;
    manager.ShowDialog();
  }
}

private bool CompletedInstall()
{
    var window = new Initialize();
    window.ShowDialog();
    return window.DoLaunchManager;
}

,App.xaml 中有以下代码

<Application x:Class="Manager.App"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Startup="App_Start">

当我注释掉检查 CompletedInstall() 的行时,ma​​nager.ShowDialog() 工作正常,并且我的配置窗口显示。 当CompletedInstall()被调用时,对ma​​nager.ShowDialog()的调用立即返回,而不显示窗口。我添加主窗口的假设是,有人决定应用程序应该只显示一个窗口。

我找到了一种解决方法,即在调用 CompletedInstall 之前设置主窗口,

        private void App_Start(object sender, StartupEventArgs e)
        {
          var manager = new WINServiceConfig();
          MainWindow = manager;

          if (CompletedInstall())
          {
            manager.ShowDialog();
          }

但这迫使我根据其使用来开发 WINServiceConfig (特别是构造函数),因为它不能指望先决条件已完成。这是不好的形式。我还能做什么来解决这个问题?

虚拟窗口?这不可能是最好的答案。可以吗??

I have the following code in my App.xaml.cs

private void App_Start(object sender, StartupEventArgs e)
{
  if ( CompletedInstall())
  {
    //using show to allow for pacifier if loading is slow
    var manager = new WINServiceConfig();
    MainWindow = manager;
    manager.ShowDialog();
  }
}

private bool CompletedInstall()
{
    var window = new Initialize();
    window.ShowDialog();
    return window.DoLaunchManager;
}

and the following in the App.xaml

<Application x:Class="Manager.App"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Startup="App_Start">

When i comment out the line that checks CompletedInstall() the manager.ShowDialog() works fine, and my configuration window shows.
When CompletedInstall() is called the call to manager.ShowDialog() returns right away without displaying the window. I added the main window on the assumption that somewhere along the line someone decided an app should only show one window.

I found a workaround by setting the main window before calling CompletedInstall

        private void App_Start(object sender, StartupEventArgs e)
        {
          var manager = new WINServiceConfig();
          MainWindow = manager;

          if (CompletedInstall())
          {
            manager.ShowDialog();
          }

but this forces me to develop WINServiceConfig (specifically the constructor) based on its use, because it cannot count on the prerequisites being completed. This is bad form. What else can i do to get around this problem?

Dummy window? That can't be the best answer. Can it??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

七禾 2024-10-10 01:03:18

您应该将 ShutdownMode 设置为 OnExplicitShutdown(至少在显示初始对话框时)。

You should set the ShutdownMode to OnExplicitShutdown (at least while showing the initial dialog).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文