The property grid support in the DSL uses the new .NET Framework 2.0 TypeDescriptionProvider class to proffer the properties shown in the grid. You need to create a new class which knows how to re-direct either Bar or Baz model element (based on your own context). When the PropertyGrid control asks you for the type descriptor, you need to supply a provider in your shape. When the shape is selected, your provider will be called and you can proffer the right model element accordingly... The following is the code snippet you need.
Hope this helps!
Patrick Tseng
DSL Tools - SDE
[TypeDescriptionProvider(typeof(MyShapeTypeDescriptionProvider))] public partial class MyShape { }
internal class MyShapeTypeDescriptionProvider : ElementTypeDescriptionProvider { protected override ElementTypeDescriptor CreateTypeDescriptor(ICustomTypeDescriptor parent, ModelElement element) { PresentationElement pel = element as PresentationElement; if (pel != null) { // See if we can find the MEL. PresentationElementTypeDescriptionProvider is meant for PresentationElement so we should // be able to find it. ModelElement mel = pel.ModelElement;
// From the selected ModelElement object, find Bar or Baz object and feed into the 2nd parameter in the following calls return new MyShapeTypeDescriptor(parent, element); }
Debug.Fail("Un-recongize object selected, calling base"); return base.CreateTypeDescriptor( parent, element); } }
/// <summary> /// Specialized type descriptor for the CommentShape class. /// </summary> public class MyShapeTypeDescriptor : ElementTypeDescriptor { /// <summary> /// Creates a new CommentShapeTypeDescriptor. /// </summary> public MyShapeTypeDescriptor(ICustomTypeDescriptor parent, ModelElement selectedElement) : base(parent, selectedElement) { } }
Patrick Tseng |