DrawingVisual Class

DrawingVisual is a visual object that can be used to render vector graphics on the screen. The content is persisted by the system.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public class DrawingVisual : ContainerVisual
<DrawingVisual .../>

The DrawingVisual type exposes the following members.

  NameDescription
Public methodDrawingVisualInitializes a new instance of the DrawingVisual class.
Top

  NameDescription
Public propertyBitmapEffect Obsolete. Gets or sets a BitmapEffect value for the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyBitmapEffectInput Obsolete. Gets or sets a BitmapEffectInput value for the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyCacheModeGets or sets a cached representation of the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyChildrenGets the child collection of the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyClipGets or sets the clipping region of the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyContentBoundsGets the bounding box for the contents of the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyDependencyObjectTypeGets the DependencyObjectType that wraps the CLR type of this instance.  (Inherited from DependencyObject.)
Public propertyDescendantBoundsGets the union of all the content bounding boxes for all of the descendants of the ContainerVisual, but not including the contents of the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyDispatcherGets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)
Public propertyDrawingGets the drawing content of the DrawingVisual object.
Public propertyEffectGets or sets the bitmap effect to apply to the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyIsSealedGets a value that indicates whether this instance is currently sealed (read-only). (Inherited from DependencyObject.)
Public propertyOffsetGets or sets the offset value of the ContainerVisual from its reference point. (Inherited from ContainerVisual.)
Public propertyOpacityGets or sets the opacity of the ContainerVisual, based on 0=transparent, 1=opaque. (Inherited from ContainerVisual.)
Public propertyOpacityMaskGets or sets a brush that specifies a possible opacity mask for the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyParentGets the parent Visual for the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyTransformGets or sets the transform that is applied to the ContainerVisual. (Inherited from ContainerVisual.)
Protected propertyVisualBitmapEffect Obsolete. Gets or sets the BitmapEffect value for the Visual. (Inherited from Visual.)
Protected propertyVisualBitmapEffectInput Obsolete. Gets or sets the BitmapEffectInput value for the Visual. (Inherited from Visual.)
Protected propertyVisualBitmapScalingModeGets or sets the BitmapScalingMode for the Visual. (Inherited from Visual.)
Protected propertyVisualCacheModeGets or sets a cached representation of the Visual. (Inherited from Visual.)
Protected propertyVisualChildrenCountGets the number of children for the ContainerVisual. (Inherited from ContainerVisual.)
Protected propertyVisualClearTypeHintGets or sets the ClearTypeHint that determines how ClearType is rendered in the Visual. (Inherited from Visual.)
Protected propertyVisualClipGets or sets the clip region of the Visual as a Geometry value. (Inherited from Visual.)
Protected propertyVisualEdgeModeGets or sets the edge mode of the Visual as an EdgeMode value. (Inherited from Visual.)
Protected propertyVisualEffectGets or sets the bitmap effect to apply to the Visual. (Inherited from Visual.)
Protected propertyVisualOffsetGets or sets the offset value of the visual object. (Inherited from Visual.)
Protected propertyVisualOpacityGets or sets the opacity of the Visual. (Inherited from Visual.)
Protected propertyVisualOpacityMaskGets or sets the Brush value that represents the opacity mask of the Visual. (Inherited from Visual.)
Protected propertyVisualParentGets the visual tree parent of the visual object. (Inherited from Visual.)
Protected propertyVisualScrollableAreaClipGets or sets a clipped scrollable area for the Visual. (Inherited from Visual.)
Protected propertyVisualTextHintingModeGets or sets the TextHintingMode of the Visual. (Inherited from Visual.)
Protected propertyVisualTextRenderingModeGets or sets the TextRenderingMode of the Visual. (Inherited from Visual.)
Protected propertyVisualTransformGets or sets the Transform value for the Visual. (Inherited from Visual.)
Protected propertyVisualXSnappingGuidelinesGets or sets the x-coordinate (vertical) guideline collection. (Inherited from Visual.)
Protected propertyVisualYSnappingGuidelinesGets or sets the y-coordinate (horizontal) guideline collection. (Inherited from Visual.)
Public propertyXSnappingGuidelinesGets or sets the X (horizontal) guideline for the ContainerVisual. (Inherited from ContainerVisual.)
Public propertyYSnappingGuidelinesGets or sets the Y (vertical) guideline for the ContainerVisual. (Inherited from ContainerVisual.)
Top

  NameDescription
Protected methodAddVisualChildDefines the parent-child relationship between two visuals. (Inherited from Visual.)
Public methodCheckAccessDetermines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Public methodClearValue(DependencyProperty)Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject.)
Public methodClearValue(DependencyPropertyKey)Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject.)
Public methodCoerceValueCoerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject. (Inherited from DependencyObject.)
Public methodEqualsDetermines whether a provided DependencyObject is equivalent to the current DependencyObject. (Inherited from DependencyObject.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFindCommonVisualAncestorReturns the common ancestor of two visual objects. (Inherited from Visual.)
Public methodGetHashCodeGets a hash code for this DependencyObject. (Inherited from DependencyObject.)
Public methodGetLocalValueEnumeratorCreates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetValueReturns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject.)
Protected methodGetVisualChildReturns a specified child Visual for the parent ContainerVisual. (Inherited from ContainerVisual.)
Public methodHitTest(Point)Returns the top-most visual object of a hit test by specifying a Point. (Inherited from ContainerVisual.)
Public methodHitTest(HitTestFilterCallback, HitTestResultCallback, HitTestParameters)Initiates a hit test on the ContainerVisual by using the HitTestFilterCallback and HitTestResultCallback objects. (Inherited from ContainerVisual.)
Protected methodHitTestCore(GeometryHitTestParameters)Determines whether a geometry value is within the bounds of the visual object. (Overrides Visual.HitTestCore(GeometryHitTestParameters).)
Protected methodHitTestCore(PointHitTestParameters)Determines whether a point coordinate value is within the bounds of the DrawingVisual object. (Overrides Visual.HitTestCore(PointHitTestParameters).)
Public methodInvalidatePropertyRe-evaluates the effective value for the specified dependency property (Inherited from DependencyObject.)
Public methodIsAncestorOfDetermines whether the visual object is an ancestor of the descendant visual object. (Inherited from Visual.)
Public methodIsDescendantOfDetermines whether the visual object is a descendant of the ancestor visual object. (Inherited from Visual.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnPropertyChangedInvoked whenever the effective value of any dependency property on this DependencyObject has been updated. The specific dependency property that changed is reported in the event data. (Inherited from DependencyObject.)
Protected methodOnVisualChildrenChangedCalled when the VisualCollection of the visual object is modified. (Inherited from Visual.)
Protected methodOnVisualParentChangedCalled when the parent of the visual object is changed. (Inherited from Visual.)
Public methodPointFromScreenConverts a Point in screen coordinates into a Point that represents the current coordinate system of the Visual. (Inherited from Visual.)
Public methodPointToScreenConverts a Point that represents the current coordinate system of the Visual into a Point in screen coordinates. (Inherited from Visual.)
Public methodReadLocalValueReturns the local value of a dependency property, if it exists. (Inherited from DependencyObject.)
Protected methodRemoveVisualChildRemoves the parent-child relationship between two visuals. (Inherited from Visual.)
Public methodRenderOpenOpens the DrawingVisual object for rendering. The returned DrawingContext value can be used to render into the DrawingVisual.
Public methodSetCurrentValueSets the value of a dependency property without changing its value source. (Inherited from DependencyObject.)
Public methodSetValue(DependencyProperty, Object)Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject.)
Public methodSetValue(DependencyPropertyKey, Object)Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject.)
Protected methodShouldSerializePropertyReturns a value that indicates whether serialization processes should serialize the value for the provided dependency property. (Inherited from DependencyObject.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodTransformToAncestor(Visual)Returns a transform that can be used to transform coordinates from the Visual to the specified Visual ancestor of the visual object. (Inherited from Visual.)
Public methodTransformToAncestor(Visual3D)Returns a transform that can be used to transform coordinates from the Visual to the specified Visual3D ancestor of the visual object. (Inherited from Visual.)
Public methodTransformToDescendantReturns a transform that can be used to transform coordinates from the Visual to the specified visual object descendant. (Inherited from Visual.)
Public methodTransformToVisualReturns a transform that can be used to transform coordinates from the Visual to the specified visual object. (Inherited from Visual.)
Public methodVerifyAccessEnforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Top

DrawingVisual is a lightweight drawing class that is used to render shapes, images, or text. This class is considered lightweight because it does not provide layout, input, focus, or event handling, which improves its performance. For this reason, drawings are ideal for backgrounds and clip art.

In order to use DrawingVisual objects, you need to create a host container for the objects. The host container object must be derived from the FrameworkElement class, which provides the layout and event handling support that the DrawingVisual class does not support. The host container object does not display any visual properties, since its main purpose is to contain child objects. For more information, see Using DrawingVisual Objects.

For a complete example showing how to create DrawingVisual objects with a host container, see the Hit Test Using DrawingVisuals Sample .

This example shows how you can create a bitmap from a Visual. A DrawingVisual is rendered with FormattedText. The Visual is then rendered to the RenderTargetBitmap creating a bitmap of the given text.

Image myImage = new Image();
FormattedText text = new FormattedText("ABC",
        new CultureInfo("en-us"),
        FlowDirection.LeftToRight,
        new Typeface(this.FontFamily, FontStyles.Normal, FontWeights.Normal, new FontStretch()),
        this.FontSize,
        this.Foreground);

DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
drawingContext.DrawText(text, new Point(2, 2));
drawingContext.Close();

RenderTargetBitmap bmp = new RenderTargetBitmap(180, 180, 120, 96, PixelFormats.Pbgra32);
bmp.Render(drawingVisual);
myImage.Source = bmp;

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft