Hallo Gurus!
Ich habe folgendes problem! Ich habe ein PropertyGrid das ich brav mit allen moeglichen objecten fuellen kann doch ich habe eine Klasse ImagePart bzw MenuImage die nicht so richtig im PropertyGrid functionieren wollen. Das Problem ist MenuImage beinhaltet eine Arralyist von ImagePart objecten es funktioniert fein ich kann die collection mit dem (...) button oeffnen kann neue element dazufuegen und weder loeschen doch ich kann die objecte nicht editieren wenn ich auf enter druecke bringt der wert wieder auf seinen halten zurueck, was mach ich falsch?
Hier mal meine MenuImage class die ich dem property grid zuweise:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38:
| [Serializable()] public class MenuImage : MenuItem { #region Member private Point position = new Point(0,0); private ArrayList imageParts = new ArrayList(); #endregion
#region Accessoirs [CategoryAttribute("Main"), DescriptionAttribute("Position for this MenuImage")] public Point Position { get { return position; } set { position = value; } } [Editor(typeof(ImagePartCollectionEditor), typeof(UITypeEditor)), CategoryAttribute("Main"),DescriptionAttribute("Collection of all image parts"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), ReadOnlyAttribute(false),RefreshProperties(RefreshProperties.All)] public ArrayList ImageParts { get { return imageParts; } set { imageParts = value; } } #endregion } |
Diese beinhaltet wie ihr set eine Arraylist mit ImageParts hier mal diese klasse:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63:
| [TypeConverterAttribute(typeof(ImagePartConverter)),DescriptionAttribute("Expand to see the ImagePart settings")] public class ImagePart { #region Member private string textureFileName = ""; private Bitmap bmp = null; private Rectangle rect = new Rectangle(0,0,256,192); private Point offset = Point.Empty; #endregion
#region Accessoirs [Editor(typeof(TgaFileNameEditor),typeof(UITypeEditor))] [CategoryAttribute("Main"), DescriptionAttribute("Filename for texture for ImagePart")] [ReadOnlyAttribute(false)] public string Texture { get { return textureFileName; } set { if (value != textureFileName) { if (value == null) Image = null; else if (value == "") Image = null; else { Image = ImageReader.ReadTga(value); textureFileName = value; } } } } [CategoryAttribute("Main"), DescriptionAttribute("Texture rectangle for texture")] [ReadOnlyAttribute(false)] public Rectangle Rectangle { get { return rect; } set { rect = value; } } [CategoryAttribute("Main"), DescriptionAttribute("Offset to the parent object position")] public Point Offset { get { return offset; } set { offset = value; } } #endregion } |
Hier noch meine CollectionEditor Klasse:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
| public class ImagePartCollectionEditor : CollectionEditor { public ImagePartCollectionEditor(Type type): base(type) { }
protected override Type CreateCollectionItemType() { return typeof(ImagePart); }
protected override object CreateInstance(Type itemType) { return new ImagePart(); } } |
So und zuletzt mein Converter:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
| public class ImagePartConverter : ExpandableObjectConverter { public override bool CanConvertTo(ITypeDescriptorContext context, System.Type destinationType) { if (destinationType == typeof(ImagePart)) return true; return base.CanConvertTo(context, destinationType); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType) { return ""; } public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) { return true; } } |
Kann einer von euch erkennen was ich falsch mache? Danke schon mal im voraus!
Stefan