DrawingAttributes Classe

Definição

Especifica a aparência de um Stroke.

public ref class DrawingAttributes : System::ComponentModel::INotifyPropertyChanged
public class DrawingAttributes : System.ComponentModel.INotifyPropertyChanged
type DrawingAttributes = class
    interface INotifyPropertyChanged
Public Class DrawingAttributes
Implements INotifyPropertyChanged
Herança
DrawingAttributes
Implementações

Exemplos

O exemplo seguinte demonstra como usar dois DrawingAttributes objetos para simular o uso de uma caneta e de um marcador no mesmo InkCanvas. O exemplo assume que o elemento raiz no ficheiro XAML é um DockPanel chamado root. Também assume que existe um Button chamado switchHighlighter e que o Click evento está ligado ao handler de eventos definido neste exemplo.

InkCanvas inkCanvas1 = new InkCanvas();
DrawingAttributes inkDA;
DrawingAttributes highlighterDA;
bool useHighlighter = false;

// Add an InkCanvas to the window, and allow the user to 
// switch between using a green pen and a purple highlighter 
// on the InkCanvas.
private void WindowLoaded(object sender, EventArgs e)
{
    inkCanvas1.Background = Brushes.DarkSlateBlue;
    inkCanvas1.DefaultDrawingAttributes.Color = Colors.SpringGreen;

    root.Children.Add(inkCanvas1);

    // Set up the DrawingAttributes for the pen.
    inkDA = new DrawingAttributes();
    inkDA.Color = Colors.SpringGreen;
    inkDA.Height = 5;
    inkDA.Width = 5;
    inkDA.FitToCurve = false;

    // Set up the DrawingAttributes for the highlighter.
    highlighterDA = new DrawingAttributes();
    highlighterDA.Color = Colors.Orchid;
    highlighterDA.IsHighlighter = true;
    highlighterDA.IgnorePressure = true;
    highlighterDA.StylusTip = StylusTip.Rectangle;
    highlighterDA.Height = 30;
    highlighterDA.Width = 10;

    inkCanvas1.DefaultDrawingAttributes = inkDA;
}

// Create a button called switchHighlighter and use 
// SwitchHighlighter_Click to handle the Click event.  
// The useHighlighter variable is a boolean that indicates
// whether the InkCanvas renders ink as a highlighter.

// Switch between using the 'pen' DrawingAttributes and the 
// 'highlighter' DrawingAttributes.
void SwitchHighlighter_Click(Object sender, RoutedEventArgs e)
{
    useHighlighter = !useHighlighter;
    
    if (useHighlighter)
    {
        switchHighlighter.Content = "Use Pen";
        inkCanvas1.DefaultDrawingAttributes = highlighterDA;
    }
    else
    {
        switchHighlighter.Content = "Use Highlighter";
        inkCanvas1.DefaultDrawingAttributes = inkDA;
    }
}
Private WithEvents inkCanvas1 As New InkCanvas()
Private inkDA As DrawingAttributes
Private highlighterDA As DrawingAttributes
Private useHighlighter As Boolean = False

' Add an InkCanvas to the window, and allow the user to 
' switch between using a green pen and a purple highlighter 
' on the InkCanvas.
Private Sub WindowLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)

    inkCanvas1.Background = Brushes.DarkSlateBlue
    inkCanvas1.DefaultDrawingAttributes.Color = Colors.SpringGreen

    ' Add the InkCanvas to the DockPanel, named root.
    root.Children.Add(inkCanvas1)

    ' Set up the DrawingAttributes for the pen.
    inkDA = New DrawingAttributes()
    With inkDA
        .Color = Colors.SpringGreen
        .Height = 5
        .Width = 5
        .FitToCurve = True
    End With

    ' Set up the DrawingAttributes for the highlighter.
    highlighterDA = New DrawingAttributes()
    With highlighterDA
        .Color = Colors.Orchid
        .IsHighlighter = True
        .IgnorePressure = True
        .StylusTip = StylusTip.Rectangle
        .Height = 30
        .Width = 10
    End With

    inkCanvas1.DefaultDrawingAttributes = inkDA

End Sub


' Create a button called switchHighlighter and use 
' SwitchHighlighter_Click to handle the Click event.  
' The useHighlighter variable is a boolean that indicates
' whether the InkCanvas renders ink as a highlighter.

' Switch between using the 'pen' DrawingAttributes and the 
' 'highlighter' DrawingAttributes when the user clicks on .
Private Sub SwitchHighlighter_Click(ByVal sender As [Object], ByVal e As RoutedEventArgs)

    useHighlighter = Not useHighlighter

    If useHighlighter Then
        switchHighlighter.Content = "Use Pen"
        inkCanvas1.DefaultDrawingAttributes = highlighterDA
    Else

        switchHighlighter.Content = "Use Highlighter"
        inkCanvas1.DefaultDrawingAttributes = inkDA
    End If

End Sub

Observações

Use a DrawingAttributes propriedade para especificar definições como cor, largura, transparência e a forma da ponta da caneta para um Stroke.

Use a DefaultDrawingAttributes propriedade para especificar os atributos de desenho para os traços adicionados a um InkCanvas. Apenas os traços adicionados após a DefaultDrawingAttributes alteração submetida mostram os atributos atualizados. A aparência dos traços que já estão no InkCanvas não muda.

Para uma lista de valores iniciais de propriedades para uma instância da DrawingAttributes classe, veja o DrawingAttributes construtor.

Utilização de Texto XAML

Esta classe não é normalmente usada em XAML.

Construtores

Name Description
DrawingAttributes()

Inicializa uma nova instância da DrawingAttributes classe.

Campos

Name Description
MaxHeight

Especifica o valor máximo permitido para a Height propriedade.

MaxWidth

Especifica o valor máximo permitido para a Width propriedade.

MinHeight

Especifica o valor mais baixo permitido para a Height propriedade.

MinWidth

Especifica o valor mais baixo permitido para a Width propriedade.

Propriedades

Name Description
Color

Obtém ou define a cor de um Stroke.

FitToCurve

Obtém ou define um valor que indica se o suavizamento de Bezier é usado para renderizar o Stroke.

Height

Obtém ou define a altura da caneta usada para desenhar o Stroke.

IgnorePressure

Obtém ou define um valor que indica se a espessura de um renderizado Stroke muda de acordo com a quantidade de pressão aplicada.

IsHighlighter

Recebe ou define um valor que indica se parece Stroke um marcador.

StylusTip

Obtém ou define a forma da caneta usada para desenhar o Stroke.

StylusTipTransform

Obtém ou define o Matrix que especifica a transformação a realizar na ponta do stylus.

Width

Obtém ou define a largura da caneta usada para desenhar o Stroke.

Métodos

Name Description
AddPropertyData(Guid, Object)

Adiciona uma propriedade personalizada ao DrawingAttributes objeto.

Clone()

Copia o DrawingAttributes objeto.

ContainsPropertyData(Guid)

Devolve um valor que indica se o identificador de dados especificado está no DrawingAttributes objeto.

Equals(Object)

Determina se o objeto especificado DrawingAttributes é igual ao objeto atual DrawingAttributes .

GetHashCode()

Serve como função de hash para um tipo específico.

GetPropertyData(Guid)

Obtém o valor da propriedade personalizada associada ao especificado Guid.

GetPropertyDataIds()

Devolve os GUIDs de quaisquer propriedades personalizadas associadas ao StrokeCollection.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
OnAttributeChanged(PropertyDataChangedEventArgs)

Eleva o AttributeChanged evento.

OnPropertyChanged(PropertyChangedEventArgs)

Ocorre quando alguma DrawingAttributes propriedade muda.

OnPropertyDataChanged(PropertyDataChangedEventArgs)

Eleva o PropertyDataChanged evento.

RemovePropertyData(Guid)

Remove a propriedade personalizada associada ao .Guid

ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

Operadores

Name Description
Equality(DrawingAttributes, DrawingAttributes)

Determina se os objetos especificados DrawingAttributes são iguais.

Inequality(DrawingAttributes, DrawingAttributes)

Determina se os objetos especificados DrawingAttributes não são iguais.

evento

Name Description
AttributeChanged

Ocorre quando uma propriedade no DrawingAttributes objeto muda.

PropertyDataChanged

Ocorre quando dados de propriedades são adicionados ou removidos do StrokeCollection.

Implementações de Interface Explícita

Name Description
INotifyPropertyChanged.PropertyChanged

Esta API suporta a infraestrutura de produtos e não é pressuposta para ser utilizada diretamente a partir do seu código.

Ocorre quando o valor de qualquer DrawingAttributes propriedade mudou.

Aplica-se a