2

コンソール アプリケーションがあります。したがって、「UserInterface.xaml」というウィンドウを開く必要があります。これはウィンドウです。

私のクラスのプログラムは次のとおりです。

class Program
{
        [STAThread]
        static void Main(string[] args)
        {        
            var userInterface = new UserInterface();
            userInterface .Show();
}

問題は、UserInterface.xaml が開かれているが、すぐに閉じられる場合です。そして、ユーザーからデータを取得するために必要です。

これは私のクラス UserInterface です:

public partial class UserInterface: Window
    {       

        public UserInterface()
        {                
            InitializeComponent();
        }

........
}

UserInterface ウィンドウを開いたままにするにはどうすればよいですか?

4

2 に答える 2

1

代わりに ShowDialog() メソッドを使用してください。

    UserInterface userInterface  = new UserInterface();
    userInterface.ShowDialog();

フォームが手動またはプログラムで閉じられるまでブロックされます。

于 2011-05-20T15:03:06.450 に答える
1

以下のように Main() を改良してみてください。

[STAThread]
static void Main(string[] args)
{
    var userInterface  = new UserInterface();

    System.Windows.Application app = new System.Windows.Application();
    app.Run(userInterface);
}
于 2011-05-20T15:04:58.587 に答える