[英]Unable to create a Collection Type Dependency Property
我正在尝试创建一个具有对象列表的自定义列表。 虽然在Xaml和后面的代码中都设置了此选项,但我得到了“错误的标记错误”。 下面是我如何设置PropertyKey和Property。
private static readonly DependencyPropertyKey ItemSourcePropertyKey = DependencyProperty.RegisterReadOnly(
"ItemSource",
typeof(List<object>),
typeof(MultiSelectComboBox),
new FrameworkPropertyMetadata(null));
public static readonly DependencyProperty ItemSourceProperty = ItemSourcePropertyKey.DependencyProperty;
字段是:
public List<object> ItemSource
{
get { return (List<object>)this.GetValue(ItemSourceProperty); }
set { this.SetValue(ItemSourceProperty, value); }
}
我得到的错误是:
{"Cannot create instance of 'Window1' defined in assembly 'GroupExpansion, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml' Line 1 Position 9."}
之前有没有人将DependencyProperty绑定到列表? 我遇到过一些教程,但是当我尝试模仿这些教程时,它只是表面上的。 列表和属性在扩展UserControl的文件中。 如果您需要更多详细信息,请询问。 我已经连续几天不习惯敲键盘了。 似乎正在转圈。
干杯
找到了解决方案,似乎依赖项属性需要附加到ObservableCollection。 然后,为了进行绑定,它必须是非只读的,以便可以删除DependencyPropertyKey并仅将其替换为DependencyProperty。 如果有人为此设置了实际页面,那将非常有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.