StrokeCollection.Draw(DrawingContext) Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Desenha os traços no StrokeCollection.
public:
void Draw(System::Windows::Media::DrawingContext ^ context);
public void Draw (System.Windows.Media.DrawingContext context);
member this.Draw : System.Windows.Media.DrawingContext -> unit
Public Sub Draw (context As DrawingContext)
Parâmetros
- context
- DrawingContext
A DrawingContext na qual desenhar o StrokeCollection.
Exemplos
O exemplo a seguir cria um elemento personalizado que exibe uma exibição em miniatura de um InkCanvas. O elemento personalizado mantém uma referência a um InkCanvas e é redesenhado quando o StrokeCollected evento ocorre.
public class InkThumbnail : FrameworkElement
{
private InkCanvas sourceInkCanvas = null;
// Get the InkCanvas that the user draws on.
public InkCanvas Source
{
get
{
return sourceInkCanvas;
}
set
{
if (sourceInkCanvas != null)
{
// Detach the event handler from the former InkCanvas.
sourceInkCanvas.StrokeCollected -= new InkCanvasStrokeCollectedEventHandler(SourceChanged);
}
sourceInkCanvas = value;
if (sourceInkCanvas != null)
{
// Attach the even handler to the InkCannvas
sourceInkCanvas.StrokeCollected += new InkCanvasStrokeCollectedEventHandler(SourceChanged);
}
}
}
// Handle the StrokeCollection event of the InkCanvas.
private void SourceChanged(object sender, InkCanvasStrokeCollectedEventArgs e)
{
// Cause the thumbnail to be redrawn.
this.InvalidateVisual();
}
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
// Draw the strokes from the InkCanvas at 1/4 of their size.
drawingContext.PushTransform(new ScaleTransform(0.25, 0.25));
if (sourceInkCanvas != null)
{
sourceInkCanvas.Strokes.Draw(drawingContext);
}
}
}
Public Class InkThumbnail
Inherits FrameworkElement
Private sourceInkCanvas As InkCanvas = Nothing
' Get the InkCanvas that the user draws on.
Public Property Source() As InkCanvas
Get
Return sourceInkCanvas
End Get
Set(ByVal Value As InkCanvas)
If Not sourceInkCanvas Is Nothing Then
' Detach the event handler from the former InkCanvas.
RemoveHandler sourceInkCanvas.StrokeCollected, AddressOf SourceChanged
End If
sourceInkCanvas = Value
If Not sourceInkCanvas Is Nothing Then
' Attach the even handler to the InkCannvas
AddHandler sourceInkCanvas.StrokeCollected, AddressOf SourceChanged
End If
End Set
End Property
' Handle the StrokeCollection event of the InkCanvas.
Private Sub SourceChanged(ByVal sender As Object, ByVal e As InkCanvasStrokeCollectedEventArgs)
' Cause the thumbnail to be redrawn.
Me.InvalidateVisual()
End Sub
Protected Overrides Sub OnRender(ByVal drawingContext As DrawingContext)
MyBase.OnRender(drawingContext)
' Draw the strokes from the InkCanvas at 1/4 of their size.
drawingContext.PushTransform(New ScaleTransform(0.25, 0.25))
If Not sourceInkCanvas Is Nothing Then
sourceInkCanvas.Strokes.Draw(drawingContext)
End If
End Sub
End Class
Aplica-se a
Colaborar conosco no GitHub
A fonte deste conteúdo pode ser encontrada no GitHub, onde você também pode criar e revisar problemas e solicitações de pull. Para obter mais informações, confira o nosso guia para colaboradores.