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.10.0 (in Microsoft.VisualStudio.Modeling.Sdk.Diagrams.10.0.dll)
Syntax
'Declaration
Public ReadOnly Property AnchoringBehavior As AnchoringBehavior
Get
public AnchoringBehavior AnchoringBehavior { get; }
public:
property AnchoringBehavior^ AnchoringBehavior {
AnchoringBehavior^ get ();
}
member AnchoringBehavior : AnchoringBehavior
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
Set the Generates Double Derived property of your shape class in the DSL Definition, and click Transform All Templates.
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.
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.
Warnung
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
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.