为什么WPF窗口没有打开
我想使程序名称青色Pembuat SOAL(青色问题制造者)我在启动事件添加到该代码:为什么WPF窗口没有打开
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];
}
}
}
但是,代码没有正常工作。这个计划有什么问题?
除了a.Activate();
之外,我会尝试添加a.ShowDialog();
或a.Show();
。
不知道你为什么使用Activate()
,但要确保它做到了你想要的。 http://msdn.microsoft.com/en-us/library/system.windows.window.activate.aspx
哎呀对不起,我不知道这是错误的。我接受 – 2012-11-18 05:13:43
使用a.Show()代替a.Activate(); 并确保您的处理程序中的App.xaml注册:
<Application
...
Startup="Application_Startup">
如果他使用'Show()'和'Startup','Window'将显示两次。在这种情况下,他应该使用'Show'或'ShowDialog'。 – eandersson 2012-08-03 12:26:34
没有StartupUri和Startup有区别:) – JleruOHeP 2012-08-03 12:35:17
啊,把这两个搞糊涂了。我只是重写'保护覆盖无效OnStartup(StartupEventArgs e)'所以永远不需要添加额外的XAML代码,以确保它拿起这样的事情。 http://*.com/questions/10166531/how-do-i-edit-the-mainwindow-constructor-of-a-wpf-application/10166597#10166597 – eandersson 2012-08-03 13:04:20
使用'a.Show()''不a.Activate()' – Snowbear 2012-08-03 08:14:00