我有一个项目叫 This.Is.My.Project
,其中包含一个命名空间 This.Is.My.Project.Namespace
.此命名空间包含一个 UserControl 类,该类派生自名为 This.Is.Another.Project.Namespace
的命名空间中的外部程序集的外部类。 .
namespace This.Is.My.Project.Namespace {
public partial class MyClass : This.Is.Another.Project.Namespace.ExternalClass {
...
}
}
现在编译器在单词
Another
下划线并提示以下消息:The type or namespace name 'Another' does not exist in the namespace 'This.Is.My.Project.This.Is' (are you missing an assembly reference?)
显然,编译器正在我的本地命名空间中寻找外部类,因为第一个“子”命名空间,即'
This.Is
' 是平等的。虽然实际上应该更像是项目名称是单个命名空间而不是四个嵌套的命名空间,如下所示:(I.Am.Not.Nested).ActualNamespace.MyClass
所以就我而言 (This.Is.My.Project).Namespace.MyClass
.我可以通过包含
using This.Is.Another.Project.Namespace
来摆脱错误背后的代码但我在 Xaml 方面遇到了同样的问题,我无法使用任何包含。<ext:ExternalClass x:Class="This.Is.My.Project.Namespace.MyClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ext="http://schemas.external.com/winfx/2008/xaml/external">
</dxe:ComboBoxEdit>
我可以从
This.Is.My.Project.Namespace
手动重命名命名空间至 That.Is.My.Project.Namespace
并消除错误,但我希望命名空间听起来尽可能接近,因为用户控件的行为非常接近。如果可能的话,我什至会将该类添加到外部命名空间中。有没有办法可以保留我的命名空间名称并摆脱这个错误,或者我必须重命名我的命名空间?
最佳答案
如果您在该 View 后面的代码中添加 using,那么它是否接受 xaml 中的命名空间?
顺便说一句,用不同的命名空间来命名不同的程序集是一种很好的做法,以最能代表它们的含义。
关于wpf - 引用的外部命名空间与本地命名空间崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53012860/