共用方式為


NodeShape.BoundsRules 屬性

命名空間:  Microsoft.VisualStudio.Modeling.Diagrams
組件:  Microsoft.VisualStudio.Modeling.Sdk.Diagrams.12.0 (在 Microsoft.VisualStudio.Modeling.Sdk.Diagrams.12.0.dll 中)

語法

'宣告
Public Overridable ReadOnly Property BoundsRules As BoundsRules
public virtual BoundsRules BoundsRules { get; }

屬性值

類型:Microsoft.VisualStudio.Modeling.Diagrams.BoundsRules

備註

覆寫您的圖案類別的 BoundsRules 限制使用者如何移動或重設大小圖案。 例如,您可以防止使用者將圖案從或特定區域,或者您可以限制寬度和高度指定範圍或比例。 規則,當使用者拖曳圖形或其邊緣或角落時,因此,使用者會看到這個虛構的移動模型有限制會根據您的規則。

這個屬性應該傳回的類別執行個體實作 BoundsRules。 您的 BoundsRules 實作應該有 M:Microsoft.VisualStudio.Modeling.Diagrams.BoundsRules.GetCompliantBounds(Microsoft.VisualStudio.Modeling.Diagrams.ShapeElement,Microsoft.VisualStudio.Modeling.Diagrams.RectangleD)方法。 當使用者拖曳圖案時,這個方法時重複呼叫。 方法會呈現的繫結,表示的大小和位置使用者嘗試設定。 它應該傳回您的規則允許的繫結。

BoundsRules ,則傳回 nullnull 參考 (即 Visual Basic 中的 Nothing),條件約束不會套用。

注意事項注意事項

如果您想要回應大小或位置的變更,會發生後,例如調整相鄰圖案的位置,請建立 ChangeRule 觀察 AbsoluteBounds 屬性。請參閱 AbsoluteBoundsDomainPropertyId 中的範例。如果您要更新存放區以外的值,請覆寫 OnAbsoluteBoundsChanged

範例

這個範例限制類別 MyShape 圖案有一個指定的最小寬度和特定指定高度與寬度比。

// MyShape is defined in DSL Definition.
public partial class MyShape 
{
    public override BoundsRules BoundsRules
    {
        get
        {
            return new MyShapeBoundsRule();
        }
    }
}
public class MyShapeBoundsRule : BoundsRules
{
    public override RectangleD GetCompliantBounds(ShapeElement shape, RectangleD proposedBounds)
    {
       // Do not modify bounds if reading from file.
        if (shape.Store.InSerializationTransaction)
          return proposedBounds;
        MyShape myShape = shape as MyShape;
        if (myShape == null) return proposedBounds;
        RectangleD approvedBounds = new RectangleD();
        // In this rule, any Location is OK:
        approvedBounds.Location = proposedBounds.Location;
        // But the height and width are constrained:
        approvedBounds.Height = Math.Max(proposedBounds.Height, 1.0);
        approvedBounds.Width = approvedBounds.Height * 1.618;
        return approvedBounds;
    }    
 }

.NET Framework 安全性

請參閱

參考

NodeShape 類別

Microsoft.VisualStudio.Modeling.Diagrams 命名空間