DrawingVisual Konstruktor

Definicja

Inicjuje nowe wystąpienie klasy DrawingVisual.

public:
 DrawingVisual();
public DrawingVisual ();
Public Sub New ()

Przykłady

W poniższym przykładzie DrawingVisual tworzony jest obiekt, a prostokąt jest rysowany w kontekście rysunku. Zwróć uwagę, że należy wywołać metodę Close , DrawingContext aby utrwała zawartość rysunku.

// 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 System.Windows.Point(160, 100), new System.Windows.Size(320, 80));
    drawingContext.DrawRectangle(System.Windows.Media.Brushes.LightBlue, (System.Windows.Media.Pen)null, rect);

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

    return drawingVisual;
}
' Create a DrawingVisual that contains a rectangle.
Private Function CreateDrawingVisualRectangle() As DrawingVisual
    Dim drawingVisual As New DrawingVisual()

    ' Retrieve the DrawingContext in order to create new drawing content.
    Dim drawingContext As DrawingContext = drawingVisual.RenderOpen()

    ' Create a rectangle and draw it in the DrawingContext.
    Dim rect As New Rect(New Point(160, 100), New Size(320, 80))
    drawingContext.DrawRectangle(Brushes.LightBlue, CType(Nothing, Pen), rect)

    ' Persist the drawing content.
    drawingContext.Close()

    Return drawingVisual
End Function

Uwagi

Podczas tworzenia DrawingVisual obiektu nie ma zawartości rysunkowej. Możesz dodać zawartość tekstu, grafiki lub obrazu, pobierając kontekst rysunku obiektu i rysując go. Kontekst rysunku jest zwracany przez wywołanie RenderOpen metody DrawingVisual obiektu.

Dotyczy