属性网格和抽象类 [英] Property Grid and Abstract Class
本文介绍了属性网格和抽象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在属性网格中显示覆盖的抽象类的对象?
例如,我有以下内容:
Hi, is there a way to display an object of overrided abstract class in property grid?
For example, I have the following:
public abstract class Creature
{
public string Height {get; set;}
public string Weight {get; set;}
public Creature();
}
public class Beast:Creature
{
public string Species {get; set;}
public Beast()
{
}
}
public class Human:Creature
{
public string Name {get; set;}
public Human() { }
}
我有一个类型为Creature的列表,其对象应在属性网格中进行编辑,但是当我使用
I have a list of type Creature, and its objects are meant to be edited in property grid, but it shows only Height and Weight when I use
propertyGrid1.SelectedObject = creatures[i]
时,它仅显示Height和Weight.
有没有办法,或者在将对象发送到属性网格之前我应该只使用(野兽)还是(人类)?
另外,有没有一种方法可以将此列表序列化为XML?
Is there a way, or should I just use (Beast) or (Human) before sending an object to property grid?
Also, is there a way this list can be serialized into XML?
推荐答案
这不是完成方法.
请参阅我给出的回答类似问题的详细说明:如何获得答复当单击PropertyGrid [ ^ ].
使用属性网格进行自定义演示非常可行,但一点也不容易.
—SA
This is not how it is done.
See detailed instructions I gave answering a similar Question: How to get response when click PropertyGrid[^].
Custom presentation using property grid is quite feasible but not easy at all.
—SA
好吧,在干净的解决方案上,它无需类型转换即可工作,也许是我的错,谢谢您的回答. 此外,在此处 [
Well, on the clean solution it works without type casting, maybe it''s my fault, thanks for your answers.
Also, found a solution for XML serializing here[^]
这篇关于属性网格和抽象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文