wpf - 引用的外部命名空间与本地命名空间崩溃
问题描述
我有一个名为 的项目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
并抱怨以下消息:
命名空间“This.Is.My.Project.This.Is”中不存在类型或命名空间名称“Another”(您是否缺少程序集引用?)
显然,编译器正在我的本地命名空间中寻找外部类,因为第一个“子”命名空间,即 ' This.Is
' 是相等的。虽然实际上它应该更像是项目名称是一个单一的命名空间而不是四个嵌套的命名空间,就像这样:(I.Am.Not.Nested).ActualNamespace.MyClass
so in my case (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
to重命名That.Is.My.Project.Namespace
并消除错误,但我希望命名空间听起来尽可能接近,因为用户控件的行为非常接近。如果可能的话,我什至会将该类添加到外部命名空间。有没有办法可以保留我的命名空间名称并摆脱这个错误,或者我必须重命名我的命名空间?
解决方案
如果您在该视图后面的代码中添加 using 怎么办,那么它是否接受 xaml 中的命名空间?
顺便说一句,使用最能代表其含义的不同名称空间命名不同的程序集是一种很好的做法。
推荐阅读
- java - SimpleJdbcRespository 实例化的我的存储库接口如何以及在哪里?
- c# - 通过从多表构建的 SQL 在 GridView 上显示数据
- javascript - 滚动时更改菜单链接颜色时出现问题
- php - 如何解决 PDO Drivers 没有价值,但 SQLite3 已经安装
- javascript - 尝试单元测试商店,如何使其工作?
- c# - 当数据网格中的行中的数据不同时,如何迭代不同的线条颜色?
- ios - ipa 中 Assets.car 的文件比 Assets.xcassets 大
- c++ - 如何大写和标题字符串
- django - Django如何让createsuperuser检查重复的电子邮件地址
- javascript - 如何正确更改父组件中的子组件 v-model 值?