System.windows和system.windows.forms

时间:2021-01-07 20:37:55

In my application I have both System.Windows(WindowsBase) and System.Windows.Forms assemblies. I have to use System.Windows.Application.

在我的应用程序中,我有System.Windows(WindowsBase)和System.Windows.Forms程序集。我必须使用System.Windows.Application。

But application is picking up the Application class from System.Windows.Forms instead.

但是应用程序正在从System.Windows.Forms中获取Application类。

I specified reference System.Windows; in code, but application is still picking up the Application class from System.Windows.Forms.

我指定了参考System.Windows;在代码中,但应用程序仍在从System.Windows.Forms中获取Application类。

Can you please help me how to refer to the "Application" class from System.Windows.

能否帮助我如何从System.Windows中引用“Application”类。

3 个解决方案

#1


1  

use the fully qualified name like below

使用如下所示的完全限定名称

System.Windows.Application app = new System.Windows.Application();

#2


1  

remove the reference to System.Windows.Forms, or else specify which you are using when you use it.

删除对System.Windows.Forms的引用,或者指定在使用它时使用的引用。

i.e.

System.Windows.MessageBox mb = new System.Windows.MessageBox();

#3


1  

When you have identical class names you need to fully qualify at least one of them with their namespace prefix.

如果您具有相同的类名,则需要使用其名称空间前缀完全限定其中一个。

Chances are you added a using directive to one of your code files like the following:

您可能会将一个using指令添加到您的一个代码文件中,如下所示:

using System.Windows.Forms;

If this is a WPF application you probably do not want to ever add a using directive to System.Windows.Forms. The same goes the opposite way if you are using a Windows Forms application.

如果这是一个WPF应用程序,您可能不希望将using指令添加到System.Windows.Forms。如果您使用的是Windows窗体应用程序,则情况正好相反。

For example, let's say you have the following code:

例如,假设您有以下代码:

using System.Windows;
using System.Windows.Forms;

...

Application myApp = new Application(); // this would throw a compile-time ambiguity error!

On the other hand you could do this:

另一方面,你可以这样做:

using System.Windows;

...

Application myApp = new Application();
System.Windows.Forms.MessageBox.Show("test");

#1


1  

use the fully qualified name like below

使用如下所示的完全限定名称

System.Windows.Application app = new System.Windows.Application();

#2


1  

remove the reference to System.Windows.Forms, or else specify which you are using when you use it.

删除对System.Windows.Forms的引用,或者指定在使用它时使用的引用。

i.e.

System.Windows.MessageBox mb = new System.Windows.MessageBox();

#3


1  

When you have identical class names you need to fully qualify at least one of them with their namespace prefix.

如果您具有相同的类名,则需要使用其名称空间前缀完全限定其中一个。

Chances are you added a using directive to one of your code files like the following:

您可能会将一个using指令添加到您的一个代码文件中,如下所示:

using System.Windows.Forms;

If this is a WPF application you probably do not want to ever add a using directive to System.Windows.Forms. The same goes the opposite way if you are using a Windows Forms application.

如果这是一个WPF应用程序,您可能不希望将using指令添加到System.Windows.Forms。如果您使用的是Windows窗体应用程序,则情况正好相反。

For example, let's say you have the following code:

例如,假设您有以下代码:

using System.Windows;
using System.Windows.Forms;

...

Application myApp = new Application(); // this would throw a compile-time ambiguity error!

On the other hand you could do this:

另一方面,你可以这样做:

using System.Windows;

...

Application myApp = new Application();
System.Windows.Forms.MessageBox.Show("test");