XAML中的自定义类给了我无法解决的标记错误
本文关键字:解决 错误 自定义 XAML | 更新日期: 2023-09-27 18:02:20
我创建了以下XAML,大致如下(为了简洁而缩短):
<Window ...
xmlns:Models="clr-namespace:Project.Presentation.Models;assembly=Project"
...>
<Window.Resources>
<Models:ProfileCollection x:Key="Profiles" />
</Window.Resources>
</Window>
ProfileCollection被定义为:
public class ProfileCollection : ObservableCollection<Profile>
{
public ProfileCollection()
{
foreach (Profile p in Configuration.Instance.Profiles)
this.Add(p);
}
// code that handles static added/removed events
}
这遵循MSDN上的XAML和自定义类中规定的要求。
然而,当我尝试编译时,我得到这个错误:
错误MC3074:标记'ProfileCollection'不存在于XML命名空间'clr-Project.Presentation.Models;assembly=Project'。第18行
我也试过:
<Window ...
xmlns:SystemCollections="clr-namespace:System.Collections;assembly=mscorlib"
...>
<Window.Resources>
<SystemCollections:ArrayList x:Key="arrayList" />
</Window.Resources>
</Window>
可以。
public class SomeList : ArrayList { public SomeList() { } }
在尝试使用这个对象时得到相同的错误。与之前的错误相同。
<Models:SomeList x:Key="arrayList" /> <!-- MC3074 -->
'ProfileCollection'
类是否放在命名空间'Project.Presentation.Models
中?此外,如果XAML和类都在'Project'
汇编,尝试从xmlns声明中删除"assembly=Project
"
我得到了同样的错误。原因是不同的。net框架(assembly是4.6.1,而我的基本项目是4.5.1)。
也许这个信息可以帮助别人(错误代码在我看来不是很精确…)