我有一个可以通过 PropertyGrid
编辑的自定义类。在该类中,我有一个自定义 Collection
(带有自定义 PropertyDescriptor
和 TypeConverter
)。
可以使用默认的集合编辑器将项目添加到集合
或从中删除。这一切都很好。但是 - 关闭 Collection Editor 后,PropertyGrid 不会更新。当我在 PropertyGrid
上手动调用 Refresh()
时,更改会反射(reflect)在 PropertyGrid 中。
如何让 PropertyGrid 在 Collection Editor 关闭时自动刷新?我之前寻求过一个解决方案,我应该将 CollectionEditor 子类化(我似乎找不到)。
请帮忙。
最佳答案
RefreshPropertiesAttribute Class
Indicates that the property grid should refresh when the associated property value changes. This class cannot be inherited.
插入自 http://msdn.microsoft.com/en-us/library/system.componentmodel.refreshpropertiesattribute.aspx
添加带有描述符的属性
Public Overrides ReadOnly Property Attributes() As System.ComponentModel.AttributeCollection
Get
Return New AttributeCollection(New Attribute() {RefreshPropertiesAttribute.Repaint})
End Get
End Property
演练:在设计时调试自定义 Windows 窗体控件 http://msdn.microsoft.com/en-us/library/5ytx0z24.aspx
关于C# 窗体 : PropertyGrid not updated when item added to Collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3014253/