How to: Access a Presentation Element from a Model Element
PresentationViewsSubject is the relationship that associates shapes and connectors to the model elements that they represent.
To navigate from a shape or a connector to the model element, use the property ModelElement. You can cast it to the type to which the shape is mapped in your DSL Definition.
ExampleShape shape = ...;
ExampleElement mel = shape.ModelElement as ExampleElement;
To navigate from a model element to a presentation element that represents it in the user interface, use the GetPresentation method. Presentation elements on diagrams are either shapes or connectors.
// using Microsoft.VisualStudio.Modeling;
// using Microsoft.VisualStudio.Modeling.Diagrams;
// using System.Linq;
ExampleShape shape = PresentationViewsSubject.GetPresentation(e1).FirstOrDefault()
as ExampleShape;
See Also
Other Resources
Change History
Date |
History |
Reason |
---|---|---|
Rewrite to clarify |
Content bug fix. |
|
July 2008 |
Added topic. |
Content bug fix. |