该方案非常简单。我有自定义控件的只读集合属性,我想在XAML中设置集合的项目。就像这样:WPF:无法在XAML中设置只读集合的项目
<l:CustomControl>
<l:CustomControl.ControlItems>
<l:CustomItem />
<l:CustomItem />
</l:CustomControl.ControlItems>
</l:CustomControl>
的ControlItems
酒店internal set
和public get
存取,并且是FreezableCollection<CustomItem>
类型。
事情是,我得到构建错误,说这是不可能的,因为我的ControlItems
属性没有可访问set
访问器。
据我所知,WPF支持这种情况(从.NET3.5SP1开始)。我错了吗?可能是什么问题?这适用于Grid.RowDefinitions
,我试着添加DesignerSerializationVisibility
属性,但它不起作用。
编辑:我注意到,我收到此错误,只有当我有一个internal
,private
或protected
设置访问器。当我完全删除访问器时,一切都很好。
感谢您花时间添加答案。 – Ben 2017-09-10 11:25:15