问题描述
所以,一切都在标题中,我只想在我的 WPF 窗口中添加一个 UserControl.看起来很简单,但 UserControl 位于同一解决方案中的另一个项目(Dll 项目)中.而且我无法引用它.
So, everything is in the title, I just want to add a UserControl in my WPF Window. It looks like easy but the UserControl is in another project (Dll project) in the same solution. And I just can't reference it.
所以,我最好的尝试是这样的:
So, my best try is something like that:
<Window xmlns:local="clr-namespace:MyWindowProject" x:Name="window"
xmlns:other="clr-namespace:MyDllProject"
x:Class="MyWindowProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<other:MyUserControl />
</Window>
我知道我快要找到它的方法了,因为我只有一个错误,并且自动完成功能正在 MyUserControl 上运行.但是,我遇到了这个奇怪的错误:名称 'MyUserControl' 不存在于命名空间clr-namespace:MyDllProject"中.
I know I am near to find how to make it because I've got just one error and the autocompletion is working on MyUserControl. But, I've got this weird error: "The name 'MyUserControl' does not exist in the namespace "clr-namespace:MyDllProject".
我确定我做错了什么,但我真的不知道是什么......
I'm sure that I'm doing something wrong, but I really don't know what...
推荐答案
xmlns:other="clr-namespace:MyDllProject"
xmlns:other="clr-namespace:MyDllProject"
上面的 import 语句表明您指向的是本地项目的命名空间.如果你想添加另一个项目(The Dll Project)的refrance,那么你必须像这样添加命名空间
The above import statement show's that you are pointing the namespace of your local project. if you want to add a refrance of the other project (The Dll Project) then you must add the namespace as like
xmlns:other="clr-namespace:MyDllProjectNamespace;assembly=MyDllProject"
xmlns:other="clr-namespace:MyDllProjectNamespace;assembly=MyDllProject"
这将指向存在于其他程序集中的命名空间.
This will point the namespace which exists in Other assembly.
请参阅此文章了解 Xaml 中的命名空间
See this Article to understand the namespaceing in Xaml
条件确保可以从其他程序集中访问 using 控件.
Condition Make sure the using control is accessible from the other assemblies.
这篇关于如何将另一个项目 (Dll) 中的 UserControl 添加到我的 WPF 解决方案中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!