简体   繁体   English

在属性网格,.net,winforms中编辑自定义只读集合时出现问题

[英]Problem editing custom readonly collection in property grid, .net, winforms

I have a custom collection, lets says COL, that derives from ObjectModel.Collection. 我有一个自定义集合,让我们说,COL是从ObjectModel.Collection派生的。

I have my own collection editor that works fine when a property, of type COL, is Read and Write enabled. 我有自己的集合编辑器,当COL类型的属性启用读取和写入时,该编辑器可以正常工作。 However, if I change the property to ReadOnly, the open editor button stops showing in the property grid. 但是,如果将属性更改为ReadOnly,则打开的编辑器按钮将停止在属性网格中显示。

As a test, I override my custom editor with the CollectionEditor, and that worked fine. 作为测试,我用CollectionEditor覆盖了自定义编辑器,并且效果很好。

So, my question is, what check is the property grid making, that CollectionEditor passes but my collection editor fails? 因此,我的问题是,CollectionEditor通过但我的集合编辑器失败了,这是对属性网格进行哪些检查?

There's not much to override in UITypeEditor, so I fear there's some hard coding going on with regards to CollectionEditor. UITypeEditor中没有太多要重写的内容,因此我担心关于CollectionEditor会进行一些硬编码。

Cheers. 干杯。

ETA: 预计到达时间:

I've answered the question below. 我已经回答了以下问题。

I've found out why it wasn't appearing and it appears to be a bug in the PropertyGrid. 我发现了为什么没有出现它,并且似乎是PropertyGrid中的错误。 The button does appear if the EditStyle is set to Modal, but does not appear if it's set to DropDown. 如果将EditStyle设置为Modal,则按钮会出现,但如果将其设置为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. 嗯,很好。

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, ...). 环顾下拉列表编辑器:它们为用户提供选择,因此结果是该属性的新值(请参见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). 当然,该值也可以用于选择一个新值(例如FileNameEditor)。

So maybe the answer is "look at your UI design". 因此,答案可能是“看看您的UI设计”。 Are you sure you should use a dropdown editor to edit the content of a reference type? 您确定要使用下拉编辑器来编辑引用类型的内容吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在.Net,Winforms中更改只读集合时,在设计时刷新属性网格。 - Refresh property grid, at Design-time, when a readonly collection changes in .Net, Winforms 属性网格中的自定义集合 - custom collection in property grid 在属性网格中编辑自定义类型 - Editing custom types in property grid 在运行时更改.NET属性网格只读属性 - Change .NET Property Grid readonly attribute at runtime 通过属性网格编辑可观察的集合 - Editing observable collection via property grid 在Winforms和.net中持久保存引用内部属性的集合的困难 - Difficulty with persisting a collection that references an internal property at design time in Winforms and .net DataGridView中的问题:datagridview对用户(WinForms)似乎是只读的 - A Problem in DataGridView : datagridview seems readonly to user (WinForms) .net中的类级别的RefreshProperties属性,winforms +错误地刷新了属性网格 - RefreshProperties attribute at class level in .net, winforms + incorrectly refreshing property grid 为什么我的属性在winforms编辑器中是只读的? - Why is my property readonly in winforms editor? 如何在自定义 UserControl(.Net 4、Winforms)上使用项目集合编辑器? - How to use an Items Collection Editor on a custom UserControl (.Net 4, Winforms)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM