C# 在 XAML 中找不到程序集引用,但在 xaml.cs 类中引用时会编译代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12885371/
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-08-10 00:49:32  来源:igfitidea点击:

Assembly reference not found in XAML, but code compiles when referenced in xaml.cs class

c#.netwpfxamlmdi

提问by Dot NET

I've got a strange problem adding a dll reference. I've got a WPF application and am trying to use the WPF MDI library: http://wpfmdi.codeplex.com/

我在添加 dll 引用时遇到了一个奇怪的问题。我有一个 WPF 应用程序,正在尝试使用 WPF MDI 库:http: //wpfmdi.codeplex.com/

As stated in the instructions (which are very vague), I right-clicked on references in VS2012, clicked on Add reference.., clicked on Browse..and added my dll which I downloaded.

如说明中所述(非常模糊),我在 VS2012 中右键单击引用,单击Add reference..,单击Browse..并添加我下载的 dll。

Next, I added the following line in the XAML of my window: xmlns:mdi="clr-namespace:WPF.MDI;assembly=WPF.MDI"as stated in the instructions.

接下来,我在窗口的 XAML 中添加了以下行:xmlns:mdi="clr-namespace:WPF.MDI;assembly=WPF.MDI"如说明中所述。

However, when trying to add an <mdi:MdiContainer>in the XAML, the following error messages are displayed:

但是,当尝试<mdi:MdiContainer>在 XAML 中添加 时,会显示以下错误消息:

The type 'mdi:MdiContainer' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

The type 'mdi:MdiContainer' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

The name "MdiContainer" does not exist in the namespace "clr-namespace:WPF.MDI;assembly=WPF.MDI".

The name "MdiContainer" does not exist in the namespace "clr-namespace:WPF.MDI;assembly=WPF.MDI".

This is my XAML:

这是我的 XAML:

<Window x:Class="QueryBuilder.Table"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mdi="clr-namespace:WPF.MDI;assembly=WPF.MDI"
        Height="300" Width="300" WindowStyle="ToolWindow" ResizeMode="NoResize" ShowInTaskbar="False">
</Window>

This problem has been frustrating me all day. I've tried almost everything imaginable. One thing worth noticing is that I've downlaoded the sample application from the library's site, and I can run it with no problems. Besides this, I have added this to the xaml.cs class of my project: WPF.MDI.MdiContainer d = new WPF.MDI.MdiContainer();and it compiles with no problems at all.

这个问题困扰了我一整天。我尝试了几乎所有可以想象的方法。值得注意的一件事是,我已经从库的站点下载了示例应用程序,并且可以毫无问题地运行它。除此之外,我已将此添加到我的项目的 xaml.cs 类中:WPF.MDI.MdiContainer d = new WPF.MDI.MdiContainer();并且它编译完全没有问题。

Please also note that my initial problem was asked here, and none of the suggestions worked. The problem has now changed however, due to the above paragraph which seems to indicate that the code is compiled successfully in the code behind, but not in the XAML file.

另请注意,这里我最初的问题,但没有任何建议有效。然而,问题现在已经改变,因为上面的段落似乎表明代码在后面的代码中编译成功,但在 XAML 文件中没有。

EDIT:I would also like to add that I am able to browse through the code of the assembly reference as shown below.

编辑:我还想补充一点,我可以浏览程序集参考的代码,如下所示。

enter image description here

enter image description here

采纳答案by Dot NET

I've finally solved the problem myself - going to leave this answer here incase someone has the same problem some time. Adding the solution itself to the reference path of the assembly solves the problem! It's a shame this isn't documented...

我终于自己解决了这个问题——如果有人在某个时候遇到同样的问题,我会把这个答案留在这里。将解决方案本身添加到程序集的参考路径中即可解决问题!很遗憾,这没有记录......

EDIT:To clarify, what I did was add the solution, rather than the dll. In other words, I added the MDI solution with all its classes. This naturally applies to DLLs where the source code is available too.

编辑:澄清一下,我所做的是添加解决方案,而不是 dll。换句话说,我添加了 MDI 解决方案及其所有类。这自然也适用于源代码可用的 DLL。

回答by Ond?ej

If Visual Studio will keep complaining and underlining even after you tried everything, simply terminate XDesProc.exe process using Task Manager and then rebuild solution. WPF and XAML support in Visual Studio is terrible underdone piece of shit.

如果即使在您尝试了所有方法后 Visual Studio 仍会继续抱怨和下划线,只需使用任务管理器终止 XDesProc.exe 进程,然后重建解决方案。Visual Studio 中的 WPF 和 XAML 支持是糟糕透顶的烂片。

回答by Rashmi S

Got sln file from http://wpfmdi.codeplex.com/.Build that project and used new .dll from bin,used that,then it worked fine for me.

http://wpfmdi.codeplex.com/.Build 那个项目得到 sln 文件并使用 bin 中的新 .dll,使用它,然后它对我来说很好用。