问题描述
所以,所有内容都在标题中,我只想在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...
推荐答案
上面的import语句表明您正在指向本地项目的名称空间。如果要添加其他项目(Dll项目)的副本,则必须像
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
这将指向存在于其他程序集中的命名空间。
This will point the namespace which exists in Other assembly.
请参阅此了解Xaml中的命名空间
See this Article to understand the namespaceing in Xaml
条件确保可以从其他程序集访问使用控件。
Condition Make sure the using control is accessible from the other assemblies.
这篇关于如何将另一个项目(Dll)中的UserControl添加到WPF解决方案中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!