-1
我使用的Form1是注册表单,Form2是实际应用程序。我需要当应用程序注册时,不再打开Form1而不是Form2。 我将这段代码从vb.net转换为c#,并且它在windowforms应用程序中运行良好,但我遇到了WPF应用程序的问题 - 双**行。我是WPF的初学者。有人可以帮我吗?WPF中的默认窗口实例
public Form1()
{
InitializeComponent();
//Added to support default instance behavour in C#
if (defaultInstance == null)
defaultInstance = this;
}
#region Default Instance
private static Form1 defaultInstance;
public static Form1 Default
{
get
{
if (defaultInstance == null)
{
defaultInstance = new Form1();
**defaultInstance.FormClosed += new FormClosedEventHandler(defaultInstance_FormClosed);**
}
return defaultInstance;
}
}
static void defaultInstance_FormClosed(object sender, FormClosedEventArgs e)
{
defaultInstance = null;
}
#endregion //Default Instance
是什么问题? – weston
问题是WPF中的FormClosedEventHandler,这段代码在WinForms中工作正常。 –
据我所知,这是导致问题的线路,但我不明白什么问题*是*。解释发生了什么;它不会编译?它在运行时是否会发生异常?或者它不是在做你期望的事情? – weston