在属性网格、.net、winforms 中编辑自定义只读集合时出现问题
我有一个自定义集合,可以说是 COL,它派生自 ObjectModel.Collection。
我有自己的集合编辑器,当 COL 类型的属性启用读写时,该编辑器可以正常工作。 但是,如果我将属性更改为只读,打开编辑器按钮将停止在属性网格中显示。
作为测试,我用 CollectionEditor 覆盖我的自定义编辑器,效果很好。
所以,我的问题是,属性网格进行什么检查,CollectionEditor 通过但我的集合编辑器失败?
UITypeEditor 中没有太多需要重写的内容,因此我担心 CollectionEditor 中存在一些硬编码。
干杯。
ETA:
我已经回答了下面的问题。
I have a custom collection, lets says COL, that derives from ObjectModel.Collection.
I have my own collection editor that works fine when a property, of type COL, is Read and Write enabled.
However, if I change the property to ReadOnly, the open editor button stops showing in the property grid.
As a test, I override my custom editor with the CollectionEditor, and that worked fine.
So, my question is, what check is the property grid making, that CollectionEditor passes but my collection editor fails?
There's not much to override in UITypeEditor, so I fear there's some hard coding going on with regards to CollectionEditor.
Cheers.
ETA:
I've answered the question below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经找到了它没有出现的原因,它似乎是 PropertyGrid 中的一个错误。
如果 EditStyle 设置为 Modal,则该按钮会出现,但如果设置为 DropDown,则不会出现。
人们可能会认为这些风格只是为了......,嗯,风格?
查看反射器,会出现此问题,因为仅当样式设置为模态时才会发生对只读属性的额外检查(例如检查它是否是引用类型 - 并启用按钮)。嗯,不错的一个。
I've found out why it wasn't appearing and it appears to be a bug in the PropertyGrid.
The button does appear if the EditStyle is set to Modal, but does not appear if it's set to DropDown.
One would have thought that the styles were just for ..., well, style?
Looking in reflector, the issue occurs because additional checks of readonly propertyies (such as checking if it's a reference type - and enabling the button) only happen if the style is set to modal. Hmmm, nice one.
我认为您在自己的答案中描述的行为不是错误,而是设计使然,坦率地说,这是非常合乎逻辑的。看看下拉编辑器:它们让用户进行选择,因此结果是属性的新值(请参阅 ColorEditor、AnchorEditor、DockEditor、CursorEditor,...)。因此该属性不能是只读的。模式编辑器更多的是编辑值(通常是引用类型),因此即使属性是只读的也可以使用。当然,这个也可以用来选择一个新值(例如 FileNameEditor)。
所以也许答案是“看看你的 UI 设计”。您确定应该使用下拉编辑器来编辑引用类型的内容吗?
I think the behavior you describe in your own answer is not a bug and is by design, and frankly it's quite logical. Look the dropdown editors around: they offer the user to make a selection and therefore the result is a new value for the property (see ColorEditor, AnchorEditor, DockEditor, CursorEditor, ...). As such the property must not be readonly. A modal editor is more to edit a value (usually a reference type) and therefore can be used even if the property is readonly. Of course, this one can also be used to select a new value (like the FileNameEditor for example).
So maybe the answer is "look at your UI design". Are you sure you should use a dropdown editor to edit the content of a reference type?