Share via


ShapeField.AnchoringBehavior Property

Describes how the content of the field should position and size itself in relation to the parent ShapeElement.

Namespace:  Microsoft.VisualStudio.Modeling.Diagrams
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.Diagrams (in Microsoft.VisualStudio.Modeling.Sdk.Diagrams.dll)

Syntax

'Declaration
Public ReadOnly Property AnchoringBehavior As AnchoringBehavior
'Usage
Dim instance As ShapeField 
Dim value As AnchoringBehavior 

value = instance.AnchoringBehavior
public AnchoringBehavior AnchoringBehavior { get; }
public:
property AnchoringBehavior^ AnchoringBehavior {
    AnchoringBehavior^ get ();
}
public function get AnchoringBehavior () : AnchoringBehavior

Property Value

Type: Microsoft.VisualStudio.Modeling.Diagrams.AnchoringBehavior

Remarks

The AnchoringBehavior describes how the ShapeField should position and size itself in relation to its parent and sibling ShapeElements.

To alter the default anchoring behavior

  1. Set the Generates Double Derived property of your shape class in the DSL Definition, and click Transform All Templates.

  2. Override InitializeDecorators() in your shape class.

    • Create a file in your DSL project, and add a partial class definition for your shape class. Insert the method in that class.
  3. Call the SetAnchor methods of the AnchoringBehavior object.

Examples

By default, a text field only occupies a single line. However, this example defines a shape in which the user can type text that “wraps” onto multiple lines. To see the wrapping behavior, we must also anchor the sides of the field to the sides of the shape.

Warning

This code will work with a DSL created from the Minimal Language solution template. Add a decorator called CommentDecorator to ExampleShape, and map it to a string property in the domain class ExampleElement. Set the Generates Double Derived property for ExampleShape in the DSL Definition, so that the InitializeDecorators method can be overridden.

  public partial class ExampleShape
  {
    // Called once for each shape instance, after InitializeShapeFields
    protected override void InitializeDecorators
      (IList<ShapeField> shapeFields, IList<Decorator> decorators)
    { // Be sure to call the base method.
      base.InitializeDecorators(shapeFields, decorators);
      // Look up the shape field, which is called "CommentDecorator":
      TextField commentField = (TextField)ShapeElement.FindShapeField(shapeFields, "CommentDecorator");
      TextField nameField = (TextField)ShapeElement.FindShapeField(shapeFields, "NameDecorator");
      // Allow multiple lines of text in the field.
      commentField.DefaultMultipleLine = true;
      // Autosize is not supported for multi-line   fields.
      commentField.DefaultAutoSize = false;
      // Anchor the field slightly inside the container shape.
      commentField.AnchoringBehavior.Clear();
      commentField.AnchoringBehavior.
        SetLeftAnchor(AnchoringBehavior.Edge.Left, 0.01);
      commentField.AnchoringBehavior.
        SetRightAnchor(AnchoringBehavior.Edge.Right, 0.01);
      commentField.AnchoringBehavior.
        SetTopAnchor(nameField, AnchoringBehavior.Edge.Bottom, 0.01);
      commentField.AnchoringBehavior.
        SetBottomAnchor(AnchoringBehavior.Edge.Bottom, 0.01);
    }
  }

.NET Framework Security

See Also

Reference

ShapeField Class

ShapeField Members

Microsoft.VisualStudio.Modeling.Diagrams Namespace