現在、私はPropertyGridを通じていくつかのクラスを構成しようとしています。クラスがプロパティとしてインターフェイスとして提供する場合、今私は値(グリッド内の右側)を表示するいくつかの問題があります。私は、グリッドが反射を使用して実際のタイプを取り、グリッド内の値を表示するのは通常の方法を使用するためだと考えました。あなたは、コンテナを見ることができるようにPropertyGridでインターフェイスプロパティを持つクラスを表示できません
public class MyContainerClass
{
// Simple properties that should be shown in the PropertyGrid
public MyInterface MyInterface { get; set; }
public MyClass MyClass { get; set; }
public object AsObject { get; set; }
public MyContainerClass()
{
// Create one instance of MyClass
var myClass = new MyClass();
// Put the instance into both properties
// (cause MyClass implements MyInterface)
MyClass = myClass;
MyInterface = myClass;
// and show it if it is declared as "object"
AsObject = myClass;
}
}
// Some kind of interface i'd like to show in the PropertyGrid.
public interface MyInterface
{
string Name { get; set; }
}
// A class that also implements the interface
// and uses some kind of TypeConverter
[TypeConverter(typeof(ExpandableObjectConverter))]
public class MyClass : MyInterface
{
// Create an instance and put something meaningful into the property.
public MyClass()
{
Name = "MyName";
}
public string Name { get; set; }
// Override ToString() to get something shown
// as value in the PropertyGrid.
public override string ToString()
{
return "Overridden ToString(): " + Name;
}
}
:デモは、単に以下のクラス階層を取り、PropertyGridの持つ単純なフォームを作成し、ここで
propertyGrid1.SelectedObject = new MyContainerClass();
を呼び出すことによって、それにオブジェクトを置くためのクラスです3つのプロパティすべてで同じオブジェクトを使用しますが、グリッド内では、クラスプロパティとオブジェクトプロパティには
ToString()
というテキストが表示されますが、インターフェイスプロパティには何も表示されません。また、TypeConverterは、正確な型を使用するプロパティでのみ使用されます。
PropertyGrid showing MyContainer http://image-upload.de/image/O2CC5e/9558e4e179.png
界面特性の背後にあるクラスのToStringメソッド()の結果を示すPropertyGridのを聞かせする方法が存在しますか?