Compartilhar via


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 a seguir demonstra como usar dois DrawingAttributes objetos para simular usando uma caneta e um realce no mesmo InkCanvas. O exemplo pressupõe que o elemento raiz no arquivo XAML é um DockPanel chamado root. Ele também pressupõe que há um Button chamado switchHighlighter e que o Click evento está conectado ao manipulador 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

Comentários

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

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

Para obter uma lista de valores de propriedade iniciais para uma instância da DrawingAttributes classe, consulte o DrawingAttributes construtor.

Uso de texto XAML

Essa classe normalmente não é usada em XAML.

Construtores

Nome Description
DrawingAttributes()

Inicializa uma nova instância da classe DrawingAttributes.

Campos

Nome Description
MaxHeight

Especifica o maior valor permitido para a Height propriedade.

MaxWidth

Especifica o maior valor permitido para a Width propriedade.

MinHeight

Especifica o menor valor permitido para a Height propriedade.

MinWidth

Especifica o menor valor permitido para a Width propriedade.

Propriedades

Nome Description
Color

Obtém ou define a cor de um Stroke.

FitToCurve

Obtém ou define um valor que indica se a suavização de Bezier é usada 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

Obtém ou define um valor que indica se a Stroke aparência é como um realce.

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 ser executada na dica da caneta.

Width

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

Métodos

Nome Description
AddPropertyData(Guid, Object)

Adiciona uma propriedade personalizada ao DrawingAttributes objeto.

Clone()

Copia o DrawingAttributes objeto.

ContainsPropertyData(Guid)

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

Equals(Object)

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

GetHashCode()

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

GetPropertyData(Guid)

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

GetPropertyDataIds()

Retorna 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 Objectatual.

(Herdado de Object)
OnAttributeChanged(PropertyDataChangedEventArgs)

Aciona o evento AttributeChanged.

OnPropertyChanged(PropertyChangedEventArgs)

Ocorre quando qualquer DrawingAttributes propriedade é alterada.

OnPropertyDataChanged(PropertyDataChangedEventArgs)

Aciona o evento PropertyDataChanged.

RemovePropertyData(Guid)

Remove a propriedade personalizada associada ao especificado Guid.

ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Operadores

Nome 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.

Eventos

Nome Description
AttributeChanged

Ocorre quando uma propriedade no DrawingAttributes objeto é alterada.

PropertyDataChanged

Ocorre quando os dados da propriedade são adicionados ou removidos do StrokeCollection.

Implantações explícitas de interface

Nome Description
INotifyPropertyChanged.PropertyChanged

Esta API dá suporte à infraestrutura do produto e não deve ser usada diretamente do seu código.

Ocorre quando o valor de qualquer DrawingAttributes propriedade é alterado.

Aplica-se a