为什么WPF窗口没有打开

时间:2012-08-03 08:01:16

标签: c# wpf window

我想制作程序名称Cyan Pembuat Soal(Cyan Question Maker)我将启动事件添加到此代码中:

using System;
using System.Windows;

namespace Cyan_Pembuat_Soal {
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application {
        private void Application_Startup(object sender, StartupEventArgs e){
            if (FindPlace(e.Args) != null) {
                Cyan_Pembuat_Soal.MainWindow a = new Cyan_Pembuat_Soal.MainWindow();
                a.Activate();
            } else {
                Cyan_Pembuat_Soal.MainWindow a = new Cyan_Pembuat_Soal.MainWindow();
                a.Activate();
                a.Closed += delegate(object senders, EventArgs es) {this.Shutdown();};
            }
        }
        private static string FindPlace(string[] a) {
            if (a.Length == 0) {
                return null;
            }
            int b = 0;
            System.Uri c;
            for (b = 0; b < a.Length; b++) {
                if(Uri.TryCreate(a[b], UriKind.RelativeOrAbsolute, out c)){
                    break;
                }
            }
            c = null;
            return a[b];
        }
    }
}

但该代码无法正常运行。这个程序有什么问题?

2 个答案:

答案 0 :(得分:1)

除了a.ShowDialog();之外,我还会尝试添加a.Show();a.Activate();

不确定您使用Activate()的原因,但请确保它符合您的要求。 http://msdn.microsoft.com/en-us/library/system.windows.window.activate.aspx

答案 1 :(得分:0)

使用a.Show()而不是a.Activate(); 并确保您的处理程序已在App.Xaml中注册:

<Application 
    ...
    Startup="Application_Startup">