如何在 PropertyGrid 中显示静态(共享)对象的属性?
我想在运行时在 PropertyGrid 中显示静态(共享)对象,但如果我尝试像这样设置网格的选定对象属性:
_propertyGrid.SelectedObject = System.Windows.Forms.Application
我收到编译错误:
“应用程序”是一种类型,不能 用作表达式。
有没有办法在 PropertyGrid 中显示静态(共享)对象或对象的属性?
I would like to display static (shared) objects at runtime in a PropertyGrid but if I try to set the selected object property of the grid like this:
_propertyGrid.SelectedObject = System.Windows.Forms.Application
I get a compilation error:
'Application' is a type and cannot be
used as an expression.
Is there a way to display a static (shared) object or the object's properties in the PropertyGrid?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从面向对象的角度来看,该赋值语句实际上没有任何意义,因为静态对象实际上不是一个对象——它只是方法和属性的集合,除了类名之外没有任何连贯性。不过,我明白你想做什么。
您需要给它一个对象实例。
我建议创建一个包装类(可能是单例),从
Application
对象公开所需的属性,并将其用作数据源。That assignment statement really doesn't make sense from an OO-perspective because a static object really isn't an object -- it's just a collection of methods and properties without any kind of coherence except for the class name. I see what you're trying to do, though.
You need to give it an object instance.
I would suggest creating a wrapper class (possibly a singleton) that exposes the properties you need from the
Application
object and using that as a data source instead.