C# 打开第二个Wpf窗口

C# 打开第二个Wpf窗口,c#,wpf,C#,Wpf,我有一个类(CoreClient.cs)来管理所有的程序,我的程序有很多wpf窗口不是同时打开的。 当CoreClient试图打开第一个窗口(Config.xaml)询问配置数据时,一切正常!! 当CoreClient尝试打开第二个窗口时,我收到一个错误。(Login.xaml)这应该是登录窗口,我尝试了其他窗口,但总是收到相同的错误。我的印象是,由于某种原因,在第一次之后我无法打开任何窗口 有什么想法吗 CoreClient.cs using System.Threading; using S

我有一个类(CoreClient.cs)来管理所有的程序,我的程序有很多wpf窗口不是同时打开的。 当CoreClient试图打开第一个窗口(Config.xaml)询问配置数据时,一切正常!! 当CoreClient尝试打开第二个窗口时,我收到一个错误。(Login.xaml)这应该是登录窗口,我尝试了其他窗口,但总是收到相同的错误。我的印象是,由于某种原因,在第一次之后我无法打开任何窗口

有什么想法吗

CoreClient.cs

using System.Threading;
using System.Windows;
using MioEngine;

namespace Client
{
    private EventWaitHandle _wait= new EventWaitHandle(false, EventResetMode.AutoReset);

    public class CoreClient
    {
      //[...]
      var _config = new Configuration(_wait);
      Application.Current.Run(_config);
      _wait.WaitOne();
      //some data from _config is taken when _config close...
      var _login = new Login(_mySocket, _wait);
      Application.Current.Run(_login);
      _wait.WaitOne();
      //[...]
    }
}
Config.xaml

using System;
using System.Net.Sockets;
using System.Threading;
using System.Windows;

namespace Client
{
    public partial class Configuration: Window
    {
        private EventWaitHandle _wait;

        public Configuration(EventWaitHandle wait)
        {
            InitializeComponent();
            _wait = wait;
            //
        }

        private void bExit_Click(object sender, EventArgs e)
        {
            //takes parameters from many textbox
            wait.Set();            
            this.Close();
        }
    }
}
Login.xaml

using System;
using System.Net.Sockets;
using System.Threading;
using System.Windows;
using MyEngine;
using MyPack;

namespace Client
{
    public partial class Login: Window
    {
        public Login(MySocket socket, EventWaitHandle wait)
        {
            InitializeComponent();   //<------ InvalidOperationException
            _wait = wait;
            //some code...
        }

        private void bExit_Click(object sender, EventArgs e)
        {      
            //Control and setup the network and makes the LOGIN 
            wait.Set();       
            this.Close();
        }
    }
}
使用系统;
使用System.Net.Sockets;
使用系统线程;
使用System.Windows;
使用MyEngine;
使用MyPack;
命名空间客户端
{
公共部分类登录:窗口
{
公共登录(MySocket套接字、EventWaitHandle等待)
{
初始化组件();//我就是这样做的
但是对于任何辅助窗口,我都必须使用用户控件或页面(而不是窗口)
但它们的外观和行为就像一扇窗户

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        NavigationWindow navWin = new NavigationWindow();
        navWin.Content = new UserControl1();
        navWin.ShowsNavigationUI = false;
        navWin.Show();
    }
}

你能告诉我你遇到了什么错误吗?InitializeComponent()上的InvalidOperationException;你能显示你用来打开两个窗口的代码吗,这也是CodeBehind或MVVMPost中的一些相关代码。特别感兴趣的是Login.xaml(Login.cs)的构造函数以及它试图做什么。展示你是如何试图打开窗户的