ImageField 類別
輕量型物件,表示可以顯示影像 Decorator 或背景的圖形部分。
繼承階層架構
System.Object
Microsoft.VisualStudio.Modeling.Diagrams.ShapeField
Microsoft.VisualStudio.Modeling.Diagrams.ImageField
命名空間: Microsoft.VisualStudio.Modeling.Diagrams
組件: Microsoft.VisualStudio.Modeling.Sdk.Diagrams.12.0 (在 Microsoft.VisualStudio.Modeling.Sdk.Diagrams.12.0.dll 中)
語法
'宣告
Public Class ImageField _
Inherits ShapeField
public class ImageField : ShapeField
ImageField 類型會公開下列成員。
建構函式
名稱 | 描述 | |
---|---|---|
![]() |
ImageField(String) | 初始化 ImageField 類別的新執行個體。 |
![]() |
ImageField(String, Image) | 初始化 ImageField 類別的新執行個體。 |
回頁首
屬性
名稱 | 描述 | |
---|---|---|
![]() |
AnchoringBehavior | 描述欄位內容應如何相對於父代 ShapeElement 自動調整本身的位置及大小。 (繼承自 ShapeField)。 |
![]() |
DefaultAccessibleDescription | 取得或設定預設可存取描述。 (繼承自 ShapeField)。 |
![]() |
DefaultAccessibleName | 取得或設定可存取物件之圖案欄位的預設名稱。 (繼承自 ShapeField)。 |
![]() |
DefaultAccessibleState | 取得可存取物件之圖案欄位的預設狀態。 (繼承自 ShapeField)。 |
![]() |
DefaultBackgroundBrushId | 取得或設定描繪圖案欄位背景的預設筆刷的 ID。 (繼承自 ShapeField)。 |
![]() |
DefaultFocusable | 取得圖案欄位,並確認它是否可以接收焦點,或提供圖案欄位接收焦點的能力。 (繼承自 ShapeField)。 |
![]() |
DefaultImage | 取得或設定與這個 ImageField 相關聯的預設影像。覆寫 GetDisplayImage 方法可以自訂預設的影像。 |
![]() |
DefaultInactiveSelectedBackgroundBrushId | 取得或設定圖案欄位的預設背景筆刷的 ID。 (繼承自 ShapeField)。 |
![]() |
DefaultPenId | 取得或設定圖案欄位所要使用的預設畫筆的 ID。 (繼承自 ShapeField)。 |
![]() |
DefaultReflectParentFocusedState | 取得子圖案欄位,並確認在其父圖案接收焦點時,它是否應該也接收焦點,或設定反映其父圖案焦點狀態的能力。 (繼承自 ShapeField)。 |
![]() |
DefaultReflectParentSelectedState | 取得子圖案欄位,並確認是否應該在選取其父圖案時也選取它,或設定反映其父圖案選取狀態的能力。 (繼承自 ShapeField)。 |
![]() |
DefaultSelectable | 取得圖案欄位,並確認它是否預設可選取,或設定圖案欄位的預設選取狀態。 (繼承自 ShapeField)。 |
![]() |
DefaultSelectedBackgroundBrushId | 取得或設定圖案欄位的預設背景筆刷的 ID。 (繼承自 ShapeField)。 |
![]() |
DefaultUnscaled | 取得或設定是否應未縮放地繪製影像 (相對於這個欄位的界限),或者影像應該調整以符合界限。 |
![]() |
DefaultVisibility | 取得圖案欄位,並確認它是否預設會出現,或設定圖案欄位的預設可見度。 (繼承自 ShapeField)。 |
![]() |
Name | 取得圖案欄位的名稱。 (繼承自 ShapeField)。 |
回頁首
方法
回頁首
備註
當您定義圖案的一位影像 Decorator,,和,當您定義影像圖案,圖案顯示的區域由 ImageField 處理。 以 ImageFields ShapeFields 和其他的使用範例,請檢查 Dsl \ GeneratedCode \在您的 DSL 方案的 Shapes.cs。
ImageField 是處理圖形內的區域的物件,例如空間指派 Decorator。 一個 ImageField 執行個體共用相同圖案類別的許多圖案之間。 ImageField 執行個體不儲存每個圖案的個別影像:相反地, GetDisplayImage(ShapeElement) 方法採用圖案做為參數,並可搜尋圖案和其模型項目的目前狀態的影像相關。
如果您想要特殊行為 (例如變數的影像,您可以從 ImageField 衍生的類別。
建立 ImageField 子類別
將父圖案類別的 [產生雙衍生] 屬性會在您的 DSL 定義的。
覆寫您的圖案類別的 InitializeShapeFields 方法。
- 在 DSL 建立專案的新程式碼檔,然後為圖案類別的部分類別定義。 覆寫方法定義於中。
檢查 InitializeShapeFields 程式碼在 DSL \ GeneratedCode \ Shapes.cs 的。
在您的覆寫方法,請呼叫基底方法以建立自己的影像欄位的類別執行個體。 使用此取代 shapeFields 清單的規則影像欄位。
範例
這個範例在圖案的模型項目的狀態圖示會變更相依。
警告
這個範例示範如何動態影像 Decorator。但是,如果您只是要切換的兩個影像之間根據模型變數的狀態,可能是較簡單的建立數個影像 Decorator,找出它們在圖形中的位置,然後設定可視性篩選條件取決於模型變數的特定值。若要設定這個篩選條件,請選取在 DSL 定義中的圖形對應,開啟 DSL 詳細資料視窗,然後按一下 Decorator 選項。
使用最小的語言範本,若要執行此範例程式碼,請建立新的 DSL 方案。 將布林值網域屬性 AlternateState 加入至 ExampleElement 網域類別。 將圖示 Decorator 加入至 ExampleShape 類別,並將其儲存至點陣圖檔。 按一下 [轉換所有範本]。 將在 DSL 專案的新程式碼檔,然後插入下列程式碼。
若要測試程式碼,請按 F5,此外,在偵錯方案,開啟範例圖表。 圖示的預設狀態應該會出現。 選取圖案並在屬性視窗中,將 [AlternateState] 屬性的值。 圖示應該就會透過旋轉 90 度,該圖案。
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagrams;
...
partial class ExampleShape
{
/// <summary>
/// Compose a list of the fields in this shape.
/// Called once for each shape class.
/// </summary>
/// <param name="shapeFields"></param>
protected override void InitializeShapeFields(IList<ShapeField> shapeFields)
{
// Fields set up according to DSL Definition:
base.InitializeShapeFields(shapeFields);
// Replace the image field:
ShapeField oldField = ShapeElement.FindShapeField(shapeFields, "IconDecorator");
shapeFields.Remove(oldField);
// Must keep the same name:
MyImageField newField = new MyImageField(oldField.Name);
shapeFields.Add(newField);
newField.DefaultImage = (oldField as ImageField).DefaultImage.Clone() as System.Drawing.Image;
}
}
public class MyImageField : ImageField
{
public MyImageField(string tag) : base(tag) { }
/// <summary>
/// Get the image for this field in the given shape.
/// </summary>
public override System.Drawing.Image GetDisplayImage(ShapeElement parentShape)
{
ExampleElement element = parentShape.ModelElement as ExampleElement;
if (element.AlternateState == true)
return AlternateImage;
else
return base.GetDisplayImage(parentShape);
}
private System.Drawing.Image alternateImage;
public System.Drawing.Image AlternateImage
{
get
{
if (alternateImage == null)
{
// Alternate image is a copy of the default, rotated by 90 degrees:
alternateImage = this.DefaultImage.Clone() as System.Drawing.Image;
alternateImage.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
}
return alternateImage;
}
}
}
}
執行緒安全
這個類型的任何 Public static (在 Visual Basic 中為 Shared) 成員都是安全執行緒。不保證任何執行個體成員是安全執行緒。