.NET PropertyGrid:使用 ExpandableObjectConverter 改变复杂对象的读/写权限
我正在尝试在 PropertyGrid 控件中编辑复杂对象。我添加 ExpandableObjectConverter (或我自己的子类,当我需要它时)作为 TypeConverter 并且它工作正常。
我似乎无法弄清楚的一件事是这一点。对象本身在网格中的旁边将有其 .ToString() 表示形式。然后,当我展开对象时,属性具有相同的属性。全部都可以编辑。我想禁用 ToString() 对象字段的编辑,但保持属性可编辑。
所以在 PropertyGrid 中它看起来像这样;
+ Color {(R,G,B,A) = (255,255,255,255)} --uneditable
Alpha 255 --editable
Blue 255 --editable
Green 255 --editable
Red 255 --editable
到目前为止我还没有找到一种方法来做到这一点。如果我尝试将其设置为只读,则整个对象将变为只读。如果我指定我自己的 ExpandableObjectConverter 并声明它无法从字符串转换,如果在 PropertyGrid 中编辑该字符串,它仍然会尝试强制转换,然后失败。
我本质上只是想要它,这样我就可以阻止最终用户编辑字符串并强制他们编辑各个属性,这样我就不必为每个类编写字符串解析器。
这是可能的,还是有另一种我没有想到的方法?
I'm trying to edit complex objects in a PropertyGrid control. I add the ExpandableObjectConverter (or my own subclass when I need it) as the TypeConverter and it works fine.
The one thing I can't seem to figure out is this. The object itself will have its .ToString() representation next to it in the Grid. Then when I expand the object the attributes have the same. All can be editable. I want to disable editing of the ToString() object field, but keep the attributes editable.
So in the PropertyGrid it would look like this;
+ Color {(R,G,B,A) = (255,255,255,255)} --uneditable
Alpha 255 --editable
Blue 255 --editable
Green 255 --editable
Red 255 --editable
So far I haven't found a way to do this. If I try to make it ReadOnly the entire object becomes read only. If I specify my own ExpandableObjectConverter and state it cannot convert from a string, if the string is edited in the PropertyGrid it will still try to cast and then fail.
I essentially just want it so I can stop end users from editing the string and forcing them to edit the individual attributes instead, so that I don't have to write a string parser for every single class.
Is this possible, or is there another way of doing this I just haven't thought of?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎可以解决问题:
This seems to do the trick: