ShapeField.AnchoringBehavior 属性

描述该字段的内容应该如何放置和调整有关父 ShapeElement 大小。

命名空间:  Microsoft.VisualStudio.Modeling.Diagrams
程序集:  Microsoft.VisualStudio.Modeling.Sdk.Diagrams.12.0(在 Microsoft.VisualStudio.Modeling.Sdk.Diagrams.12.0.dll 中)

语法

声明
Public ReadOnly Property AnchoringBehavior As AnchoringBehavior
public AnchoringBehavior AnchoringBehavior { get; }

属性值

类型:Microsoft.VisualStudio.Modeling.Diagrams.AnchoringBehavior

备注

AnchoringBehavior 描述 ShapeField 应如何相对于其父级以及同级 ShapeElements 定位和大小。

修改锚定的默认行为

  1. 设置属性 生成派生的双重 在 DSL 定义的类形状,然后单击 转换所有模板 (T)

  2. 重写在类形状的 InitializeDecorators()。

    • 创建在 DSL 项目的文件,而形状添加类的分部类定义。 插入该类的方法。
  3. 调用 AnchoringBehavior 对象的 SetAnchor 方法。

示例

默认情况下,文本字段只占用一行。 但是,此示例定义用户可以输入文本“包装”到多行上的一个形状。 若要查看打包的行为,必须还锚定字段的端到形状的一端。

警告

此代码与最小的语言解决方案模板创建的 DSL 一起使用。添加装饰性器调用 CommentDecorator 为 ExampleShape,并将其映射到在域类 ExampleElement的字符串属性。设置属性 生成派生的双重 在 DSL 定义的 ExampleShape,因此,可以将 InitializeDecorators 方法重写。

  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 安全性

请参阅

参考

ShapeField 类

Microsoft.VisualStudio.Modeling.Diagrams 命名空间