wpf Application.Current.Shutdown(); 在未引用的程序集中定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15434636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:06:37  来源:igfitidea点击:

Application.Current.Shutdown(); is defined in an assembly not referenced

c#wpfvisual-studio-2010

提问by Joetjah

I'm getting the error:

我收到错误:

Error 1 The type 'System.Windows.Markup.IQueryAmbient' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

错误 1 ​​在未引用的程序集中定义了类型“System.Windows.Markup.IQueryAmbient”。您必须添加对程序集“System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的引用。

When doing the following:

执行以下操作时:

public void ExitApplication()
{
    Application.Current.Shutdown();
}

The project is targeted to .NET 4.0, my Visual Studio is 2010, I tried adding

该项目针对.NET 4.0,我的Visual Studio是2010,我尝试添加

using System.Windows.Markup;with no succes, and

using System.Windows.Markup;没有成功,并且

using System.Xaml;where Xaml doesn't exist in namespace System.

using System.Xaml;Xaml 在命名空间系统中不存在的地方。

What should I do to fix this?

我该怎么做才能解决这个问题?

回答by DHN

Well ok, I guess your issue is solved when you add System.Xaml.dllas reference to your project. The interface is declared there. Here is the doc.

好吧,我想当您添加System.Xaml.dll作为对您的项目的引用时,您的问题就解决了。接口在那里声明。这是文档

回答by Antonio Bakula

Add System.Xaml.dll to project references.

将 System.Xaml.dll 添加到项目引用。

回答by TimVK

You need to add a referenceto System.Xamlin your main application project. Using System.Xamlis not needed to be in your code.

您需要在主应用程序项目中添加一个referenceto System.XamlUsing System.Xaml不需要出现在您的代码中。