ImageField Class
Lightweight object that represents a part of a shape that can display image decorators or backgrounds.
Inheritance Hierarchy
System.Object
Microsoft.VisualStudio.Modeling.Diagrams.ShapeField
Microsoft.VisualStudio.Modeling.Diagrams.ImageField
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 Class ImageField _
Inherits ShapeField
public class ImageField : ShapeField
public ref class ImageField : public ShapeField
type ImageField =
class
inherit ShapeField
end
public class ImageField extends ShapeField
The ImageField type exposes the following members.
Constructors
Name | Description | |
---|---|---|
ImageField(String) | Initializes a new instance of the ImageField class. | |
ImageField(String, Image) | Initializes a new instance of the ImageField class. |
Top
Properties
Name | Description | |
---|---|---|
AnchoringBehavior | Describes how the content of the field should position and size itself in relation to the parent ShapeElement. (Inherited from ShapeField.) | |
DefaultAccessibleDescription | Gets or sets the default accessible description. (Inherited from ShapeField.) | |
DefaultAccessibleName | Gets or sets the default name of the shape field for the accessible object. (Inherited from ShapeField.) | |
DefaultAccessibleState | Gets the default state of the shape field for the accessible object. (Inherited from ShapeField.) | |
DefaultBackgroundBrushId | Gets or sets the ID of the default brush to paint the background of the shape field. (Inherited from ShapeField.) | |
DefaultFocusable | Gets the shape field and verifies whether it can receive focus, or gives the shape field the ability to receive focus. (Inherited from ShapeField.) | |
DefaultImage | Gets or sets the default image associated with this ImageField. The default image can be customized by overriding the GetDisplayImage method. | |
DefaultInactiveSelectedBackgroundBrushId | Gets or sets the ID of the default background brush for the shape field. (Inherited from ShapeField.) | |
DefaultPenId | Gets or sets the ID of the default pen to use for the shape field. (Inherited from ShapeField.) | |
DefaultReflectParentFocusedState | Gets the child shape field and verifies whether it should receive focus when its parent shape receives focus or sets the ability to reflect the focus state of its parent shape. (Inherited from ShapeField.) | |
DefaultReflectParentSelectedState | Gets the child shape field and verifies whether it should be selected when its parent shape is selected or sets the ability to reflect the selection state of its parent shape. (Inherited from ShapeField.) | |
DefaultSelectable | Gets the shape field and verifies whether it can be selected by default or sets the default selection state of the shape field. (Inherited from ShapeField.) | |
DefaultSelectedBackgroundBrushId | Gets or sets the ID of the default background brush for the shape field. (Inherited from ShapeField.) | |
DefaultUnscaled | Gets or sets whether image should be drawn unscaled with regards to the bounds of this field or image should be scaled to fit the bounds. | |
DefaultVisibility | Gets the shape field and verifies whether it appears by default or sets the default visibility of the shape field. (Inherited from ShapeField.) | |
Name | Gets the name of the shape field. (Inherited from ShapeField.) |
Top
Methods
Name | Description | |
---|---|---|
AccessibleDoDefaultAction | Performs the default action for the accessible object. (Inherited from ShapeField.) | |
AllowInPlaceEditorAutoSize | Enables the in-place editor to be automatically sized in the shape field. (Inherited from ShapeField.) | |
AssociateValueWith(Store, AssociatedPropertyInfo) | Associates the shape field with a domain property that is assigned to a shape element. (Inherited from ShapeField.) | |
AssociateValueWith(Store, Guid) | Associates the shape field with a domain property that is assigned to a shape element. (Inherited from ShapeField.) | |
AssociateValueWith(Store, Guid, AssociatedPropertyInfo) | Associates the shape field with a domain property that is assigned to a shape element. (Inherited from ShapeField.) | |
AssociateVisibilityWith(Store, AssociatedPropertyInfo) | Associates the visibility of the shape field with a domain property that is assigned to a shape element. (Inherited from ShapeField.) | |
AssociateVisibilityWith(Store, Guid) | Associates the visibility of the shape field with a domain property that is assigned to a shape element. (Inherited from ShapeField.) | |
AssociateVisibilityWith(Store, Guid, AssociatedPropertyInfo) | Associates the visibility of the shape field with a domain property that is assigned to a shape element. (Inherited from ShapeField.) | |
CanEditValue | Gets the shape field and verifies whether it can be edited. (Inherited from ShapeField.) | |
CommitPendingEdit | Commits the pending edit. (Inherited from ShapeField.) | |
DoHitTest | Performs a hit test on a specified point in the diagram to determine whether the point is in the bounds of the shape field. (Inherited from ShapeField.) | |
DoKeyboardNavigation | Navigates in the shape field by using the keyboard. (Inherited from ShapeField.) | |
DoPaint | Draws the contents of the ShapeField. (Overrides ShapeField.DoPaint(DiagramPaintEventArgs, ShapeElement).) | |
EditValue(ShapeElement, DiagramClientView) | Opens the in-place editor for the shape field. (Inherited from ShapeField.) | |
EditValue(ShapeElement, DiagramClientView, PointD) | Opens the in-place editor for the shape field. (Inherited from ShapeField.) | |
Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
FindFirstChild | Locates the first child shape field in the parent shape field. (Inherited from ShapeField.) | |
FindLastChild | Locates the last child shape field in the parent shape field. (Inherited from ShapeField.) | |
FindNextChild | Locates the next child shape field in the parent shape field. (Inherited from ShapeField.) | |
FindNextInChildSubFields | Locates the next child shape field in the navigation sequence. (Inherited from ShapeField.) | |
FindPreviousChild | Locates the previous child shape field in the parent shape field. (Inherited from ShapeField.) | |
FindPreviousInChildSubFields | Locates the previous child shape field in the navigation sequence. (Inherited from ShapeField.) | |
Focused | Gets the shape field and verifies whether it has focus. (Inherited from ShapeField.) | |
GetAccessibilityObject | Gets the accessibility object that is assigned to the shape field. (Inherited from ShapeField.) | |
GetAccessibleChild | Gets the Accessibility object for the child shape field. (Inherited from ShapeField.) | |
GetAccessibleChildCount | Gets the number of Accessibility objects that are assigned to the parent shape field and its child shape fields. (Inherited from ShapeField.) | |
GetAccessibleDefaultActionDescription | Gets the default purpose of the shape field for the accessible object. (Inherited from ShapeField.) | |
GetAccessibleDescription | Returns the default accessible description for an image field. (Overrides ShapeField.GetAccessibleDescription(ShapeElement).) | |
GetAccessibleHelp | Gets the shape field Help for the accessible object. (Inherited from ShapeField.) | |
GetAccessibleHelpTopicFileName | Gets a topic in the Help for the accessible object. (Inherited from ShapeField.) | |
GetAccessibleHelpTopicId | Gets the ID that is assigned to the Help topic for the accessible object. (Inherited from ShapeField.) | |
GetAccessibleName | Returns the default accessible name for an image field. (Overrides ShapeField.GetAccessibleName(ShapeElement).) | |
GetAccessibleRole | Retrieves the accessible role of this ShapeField. (Overrides ShapeField.GetAccessibleRole(ShapeElement).) | |
GetAccessibleState | Gets the state of the shape field for the accessible object. (Inherited from ShapeField.) | |
GetAccessibleValue | Gets the value in the shape field for the accessible object. (Inherited from ShapeField.) | |
GetActiveInPlaceEditor | Gets the in-place editor that is active. (Inherited from ShapeField.) | |
GetBackgroundBrush | Gets the brush that draws the background for the shape element to which this shape field is assigned. (Inherited from ShapeField.) | |
GetBackgroundBrushId | Gets the ID of the brush that draws the background for the shape element to which this shape field is assigned. (Inherited from ShapeField.) | |
GetBounds | Gets the bounds for the shape field. (Inherited from ShapeField.) | |
GetCursor | Gets the pointer that appears when the mouse is pointing to the shape field. (Inherited from ShapeField.) | |
GetDisplayImage | Gets the image to be displayed by this field. | |
GetFocusable | Gets the shape field and verifies whether it can receive focus. (Inherited from ShapeField.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetInPlaceEditorBounds | Gets the bounds for the in-place editor. (Inherited from ShapeField.) | |
GetMaximumInPlaceEditorSize | Gets the maximum bounds for the in-place editor. (Inherited from ShapeField.) | |
GetMinimumInPlaceEditorSize | Gets the minimum bounds for the in-place editor. (Inherited from ShapeField.) | |
GetMinimumSize | Returns the minimum size of the ImageField. (Overrides ShapeField.GetMinimumSize(ShapeElement).) | |
GetPen | Gets the pen that draws the shape element to which the shape field is assigned. (Inherited from ShapeField.) | |
GetPenId | Gets the ID of the pen that draws the shape element to which the shape field is assigned. (Inherited from ShapeField.) | |
GetPotentialMouseAction | Gets the mouse action to activate when the user next clicks a specific point on the diagram. (Inherited from ShapeField.) | |
GetSelectable | Gets the shape field and verifies whether it can be selected. (Inherited from ShapeField.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
GetUnscaled | Gets whether the image should be drawn unscaled or not. | |
GetValue | Gets the value in the shape field. (Inherited from ShapeField.) | |
GetValueDomainPropertyInfo | Gets the domain property that is assigned to the value in the shape field. (Inherited from ShapeField.) | |
GetVisible | Gets the shape field and verifies whether it appears. (Inherited from ShapeField.) | |
HasFocusedAppearance | Gets the shape field and verifies whether it should appear to have the focus. (Inherited from ShapeField.) | |
HasPendingEdit | Gets the shape field and verifies whether its in-place editor is active and a change is pending. (Inherited from ShapeField.) | |
HasSelectedAppearance | Gets the shape field and verifies whether it appears to be selected. (Inherited from ShapeField.) | |
IsNavigationKey(Char) | Gets the key that the user pressed and verifies whether it can be used to navigate between shape fields. (Inherited from ShapeField.) | |
IsNavigationKey(Keys) | Gets the keys that the user pressed and verifies whether they can be used to navigate between shape fields. (Inherited from ShapeField.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
NavigateAscend | Moves the focus to the previous shape field in the navigation sequence for the selected shapes. (Inherited from ShapeField.) | |
NavigateDescend | Moves the focus to the next shape field in the navigation sequence for the selected shapes. (Inherited from ShapeField.) | |
NavigateToFirst | Moves the focus to the first shape field in the navigation sequence for the selected shapes. (Inherited from ShapeField.) | |
NavigateToLast | Moves the focus to the last shape field in the navigation sequence for the selected shapes. (Inherited from ShapeField.) | |
NavigateToNext | Moves the focus to the next shape field in the navigation sequence for the selected shapes. (Inherited from ShapeField.) | |
NavigateToPrevious | Moves the focus to the previous shape field in the navigation sequence for the selected shapes. (Inherited from ShapeField.) | |
OnBeginEdit | Alerts listeners when in-place editing has begun. (Inherited from ShapeField.) | |
OnClick | Alerts listeners when the user has clicked a shape field. (Inherited from ShapeField.) | |
OnDoubleClick | Alerts listeners when the user has double-clicked a shape field. (Inherited from ShapeField.) | |
OnEndEdit | Alerts listeners when in-place editing has completed. (Inherited from ShapeField.) | |
OnKeyDown | Alerts listeners when the user has held down a key when pointing to a shape field. (Inherited from ShapeField.) | |
OnKeyPress | Alerts listeners when the user has pressed a key when pointing to a shape field. (Inherited from ShapeField.) | |
OnKeyUp | Alerts listeners when the user has released a key when pointing to a shape field. (Inherited from ShapeField.) | |
OnMouseDown | Alerts listeners when the user is holding down the mouse over a shape field. (Inherited from ShapeField.) | |
OnMouseMove | Alerts listeners when the mouse has been moved over a shape field. (Inherited from ShapeField.) | |
OnMouseUp | Alerts listeners when the user has released the mouse button over a shape field. (Inherited from ShapeField.) | |
OnMouseWheel | Alerts listeners when the mouse has been rotated over a shape field. (Inherited from ShapeField.) | |
Selected | Gets the shape field and verifies whether it is selected. (Inherited from ShapeField.) | |
SetSelectionRange | Sets the selection to a range of child shape fields. (Inherited from ShapeField.) | |
SetValue | Assigns the specified value to a shape field. (Inherited from ShapeField.) | |
SetVisible | Sets the visibility of the shape field. (Inherited from ShapeField.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Top
Remarks
When you define an image decorator in a shape, and when you define an image shape, the area in which the shape is displayed is managed by an ImageField. For examples of the initialization of ImageFields and other ShapeFields, inspect Dsl\GeneratedCode\Shapes.cs in your DSL solution.
An ImageField is an object that manages an area within a shape, such as the space assigned to a decorator. One ImageField instance is shared between many shapes of the same shape class. The ImageField instance does not store a separate image for each shape: instead, the GetDisplayImage(ShapeElement) method takes the shape as a parameter, and can look up the image dependent on the current state of the shape and its model element.
If you want special behavior such as a variable image, you can create your own class derived from ImageField.
To create a subclass of ImageField
Set the Generates Double Derived property of the parent shape class in your DSL Definition.
Override the InitializeShapeFields method of your shape class.
- Create a new code file in the DSL project, and write a partial class definition for the shape class. Override the method definition there.
Inspect the code of InitializeShapeFields in DSL\GeneratedCode\Shapes.cs.
In your override method, call the base method and then create an instance of your own image field class. Use this to replace the regular image field in the shapeFields list.
Examples
This example makes an icon change dependent on the state of the shape’s model element.
Warning
This example demonstrates how to make a dynamic image decorator. But if you only want to switch between one or two images depending on the state of a model variable, it is simpler to create several image decorators, locate them in the same position on the shape, and then set the Visibility filter to depend on specific values of the model variable. To set this filter, select the shape map in the DSL Definition, open the DSL Details window, and click the Decorators tab.
To run this example code, create a new DSL solution using the Minimal Language template. Add a Boolean domain property AlternateState to the ExampleElement domain class. Add an icon decorator to the ExampleShape class, and set its image to a bitmap file. Click Transform All Templates. Add a new code file in the DSL project, and insert the following code.
To test the code, press F5 and, in the debugging solution, open a sample diagram. The default state of the icon should appear. Select the shape and in the Properties window, change the value of the AlternateState property. The icon should then appear rotated through 90 degrees, on that shape.
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;
}
}
}
}
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.