所以,一切都在标题中,我只想在我的 WPF 窗口中添加一个 UserControl。它看起来很简单,但 UserControl 位于同一解决方案的另一个项目(Dll 项目)中。而且我无法引用它。
所以,我最好的尝试是这样的:
<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 上运行。但是,我遇到了这个奇怪的错误:“命名空间“clr-namespace:MyDllProject”中不存在名称“MyUserControl”。
我确定我做错了什么,但我真的不知道是什么......
最佳答案
xmlns:other="clr-namespace:MyDllProject"
上面的 import 语句表明您正在指向本地项目的命名空间。如果你想添加另一个项目(The Dll Project)的引用,那么你必须像这样添加命名空间
xmlns:other="clr-namespace:MyDllProjectNamespace;assembly=MyDllProject"
这将指向存在于其他程序集中的命名空间。
查看此 Article了解 Xaml 中的命名空间
条件 确保 using 控件可从其他程序集访问。
关于c# - 如何将我的 UserControl 从另一个项目 (Dll) 添加到我的 WPF 解决方案中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17422940/