【发布时间】:2017-01-24 18:38:18
【问题描述】:
我创建了一个包含多个 UserControls 的 wpf 应用程序,其中一个我想要一个另一个用户控件的列表,我从可观察的集合中使用它来管理它,但是当我在设计器中将项目添加到此列表并构建解决方案时,用户控件消失并显示错误。
Cannot create an instance of " Component".
例外: 无法创建“组件”的实例。
错误: 组件项目。组件'没有由 URI '/Project;component/component.xaml' 标识的资源。
我创建 observableCollection,如果我创建 observableCollection 问题得到解决,但我需要收集我的 userControl。 当我运行应用程序时,我没有问题,只是在设计器中出现了问题。
已编辑:
public partial class my_Component : UserControl
{
private ObservableCollection<user_Component> userCollection;
public ObservableCollection<user_Component> UserCollection
{
get { return userCollection; }
}
public my_Component()
{
userCollection = new ObservableCollection<user_Component>();
}
In xaml:
<cc:my_Component >
<cc:my_Component.userCollection>
<cc:user_Component/>
</cc:my_Component.userCollection>
</cc:my_Component>
【问题讨论】:
-
1.设计师展示了很多没有任何意义的错误。 2.这里的绝大多数问题(包括你的)都需要代码才能被分析和回答。
-
你的类名是
my_Component,但你的构造函数是Component?这是导致问题的实际代码还是只是问题中的拼写错误? -
对不起,这只是一个问题,我的代码可以执行,问题只是在设计器中我有那个错误,如果我清理并重建它已经解决了,但是如果我删除我的用户控件并添加一个从工具箱中新建它并在它的列表中添加一些用户控件再次出现错误:(
标签: c# wpf xaml user-controls