访问 UITypeEditor 的 EditValue 中的附加上下文数据
我正在调整 WinForms 应用程序。该应用程序有一个包含 PropertyGrid
的 Form
。将对象分配给 SelectedObject
属性,以便属性网格显示该对象的属性。
分配的对象类型有一个属性,该属性带有指定 UITypeEditor
的 EditorAttribute
。
UITypeEditor
的此实现在其对 GetEditStyle
方法的重写中返回 UITypeEditorEditStyle.Drop
。它的 EditValue
方法显示一个 ListBox
,可以从中分配实例属性的值。
到目前为止一切都很好。
现在我有一个额外的要求,要求根据托管 PropertyGrid
的 Form
所持有的其他状态来修改列表中的可用项目。我不知道如何将此上下文信息传递给 EditValue
方法。
即使我尝试将其转换为更具体的类型, context
参数上似乎也没有任何内容。我也无法弄清楚如何添加一些其他服务以从 provider
检索。
有什么想法吗?
I'm tweaking a WinForms application. This application has a Form
that contains a PropertyGrid
. An object is assigned to the SelectedObject
property so that the property grid displays the properties for the object.
The type of the object assigned has a property that carries an EditorAttribute
specifying a UITypeEditor
.
This implementation of UITypeEditor
returns UITypeEditorEditStyle.Drop
in its override of GetEditStyle
method. Its EditValue
method displays a ListBox
from which a value for the instance property can be assigned.
All well an good so far.
Now I have an additional requirement which calls for the available items in the list to be modified based on other state held by the Form
hosting the PropertyGrid
. I can't work out how to get this contextual information to the EditValue
method.
There doesn't seem to be anything on the context
parameter even if I try casting it to more specific types. Neither can I work out how to add some other Service to retrieve from the provider
.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了类似的情况,我想将一个对象注入到我的自定义 UITypeEditor 的构造函数中。
我在 此处,把所有的功劳都归功于他。它使用 TypeDescriptionProvider。
这是完整的代码集。
迈克尔
I was in similar situation, I wanted to inject an object into my custom UITypeEditor's constructor.
I followed Nicolas Cadilhac comment in Here, GIVE HIM ALL THE CREDIT. It uses TypeDescriptionProvider.
Here is the complete set of code.
Michael
我想知道您想要做的事情是否会通过
GetStandardValues
作为TypeConverter
更好?但无论哪种方式,context.Instance
和context.PropertyDescriptor
似乎都在快速测试中填充(对于GetEditStyle
code> 和EditValue
):或者作为类型转换器:
I wonder if what you are trying to do would would better as a
TypeConverter
viaGetStandardValues
? But either way, bothcontext.Instance
andcontext.PropertyDescriptor
seem to be populated in a quick test (for bothGetEditStyle
andEditValue
):Or as a type-converter:
在重写的 EditValue 方法中,
context.Container
将提供编辑器所属的对象。context.Container.Components
属性将列出包含表单及其所有子项的所有控件。In the overridden EditValue method,
context.Container
will provide the object that the editor belongs to. Thecontext.Container.Components
property will list out all the controls which includes the form and all of its children.