Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DrawingVisual.DrawingVisual Constructor

Initializes a new instance of the DrawingVisual class.

Namespace: System.Windows.Media
Assembly: PresentationCore (in presentationcore.dll)

public DrawingVisual ()
public DrawingVisual ()
public function DrawingVisual ()
You cannot use constructors in XAML.

When you create a DrawingVisual object, it has no drawing content. You can add text, graphic, or image content by retrieving the drawing context of the object and drawing into it. A drawing context is returned by calling the RenderOpen method of a DrawingVisual object.

In the following example, a DrawingVisual object is created, and a rectangle is drawn into its drawing context. Notice that you must call the Close method of the DrawingContext to persist drawing content.

// Create a DrawingVisual that contains a rectangle.
private DrawingVisual CreateDrawingVisualRectangle()
{
    DrawingVisual drawingVisual = new DrawingVisual();

    // Retrieve the DrawingContext in order to create new drawing content.
    DrawingContext drawingContext = drawingVisual.RenderOpen();

    // Create a rectangle and draw it in the DrawingContext.
    Rect rect = new Rect(new Point(160, 100), new Size(320, 80));
    drawingContext.DrawRectangle(Brushes.LightBlue, (Pen)null, rect);

    // Persist the drawing content.
    drawingContext.Close();

    return drawingVisual;
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft