使用具有运行时类型的PropertyGrid集合编辑器。 [英] Using PropertyGrid Collections editors with run-time types.

查看:237
本文介绍了使用具有运行时类型的PropertyGrid集合编辑器。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PropertyGrid来填充一个复杂的对象,我在编译时不知道它们的类型。对于集合,PropertyGrid调用默认属性网格集编辑器。我需要拦截或替换它,以便我可以对集合中字段的编辑做出反应。如果我知道类型,这并不困难,因为我可以编写一个定制的集合编辑器,但我可以在不知道类型的情况下实现这一点吗?例如,我可以编写一个所有集合都将使用的CollectionEditor吗?



所有集合的类型为Generic.List< T>变量T.

I am using PropertyGrid to populate a complex object, whose types I do not know at compile time. For collections, the PropertyGrid invokes the default property grid collection editor. I need to intercept or replace that so I can react to edits of the fields within the collection. This would not be difficult if I knew the types, as I could write a bespoke collection editor, but can I achieve this without knowing the types? For example, could I write one CollectionEditor that all collections will utilize?

All the collections are of type Generic.List<T> for varying T.

推荐答案

PropertyGrid 的自定义非常可行但不那么容易。但是,你只想开发自己的编辑器,这要简单得多。您为类型开发编辑器,编写特殊属性并将其应用于类型。如果这样做,则无需将此属性添加到这些类型的成员中。这会自动覆盖所有类型的会员使用您的特殊类型 - 所有这些(提前未知)会员将使用您的编辑。



如何做到这一点?如果有一个非常详细的解释与完整的源代码,这是相对简短的。至少这个想法很容易被抓住。请参阅我最近的文章: PropertyGrid和Visual Studio的按位枚举编辑器 [ ^ ]。



如果您对 PropertyGrid 自定义有其他疑问,我会尽力回答,但是如果没有源代码,某些自定义就很难解释。我确实有这样的代码,但是它需要花费很多时间才能用于文章。



-SA
Customization of PropertyGrid is quite doable but not so easy. However, it you just want to develop your own editor, this is much simpler. You develop the editor for your type(s), write a special attribute and apply it to the type(s). If you do so, you won't need to add this attribute to the members of those type. This will automatically cover all types using your special types for their members — all such (unknown in advance) members will use your editor.

How to do this? If have a very detailed explanation with full source code, which is relatively short and easy. It least the idea is easy to catch. Please see my recent article: Bitwise Enumeration Editor for PropertyGrid and Visual Studio[^].

If you have other questions on PropertyGrid customization, I'll try to answer, but some sort of customization is relatively hard to explain without source code. I do have such code, but it will take a lot of time to adopt it for an article.

—SA


这篇关于使用具有运行时类型的PropertyGrid集合编辑器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆