DrawingAttributes 类

定义

指定 Stroke 的外观Specifies the appearance of a Stroke

public ref class DrawingAttributes : System::ComponentModel::INotifyPropertyChanged
public class DrawingAttributes : System.ComponentModel.INotifyPropertyChanged
type DrawingAttributes = class
    interface INotifyPropertyChanged
Public Class DrawingAttributes
Implements INotifyPropertyChanged
继承
DrawingAttributes
实现

示例

下面的示例演示如何使用两个 DrawingAttributes 对象来模拟在同一 InkCanvas上使用笔和荧光笔。The following example demonstrates how to use two DrawingAttributes objects to simulate using a pen and a highlighter on the same InkCanvas. 该示例假设 XAML 文件中的根元素是名为 rootDockPanelThe example assumes the root element in the XAML file is a DockPanel called root. 它还假定存在一个名为 switchHighlighter ButtonClick 事件连接到本示例中定义的事件处理程序。It also assumes that there is a Button called switchHighlighter and that the Click event is connected to the event handler defined in this example.

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

注解

使用 "DrawingAttributes" 属性可指定 Stroke的触笔笔尖的设置,如颜色、宽度、透明度和形状。Use the DrawingAttributes property to specify settings such as color, width, transparency, and the shape of the stylus tip for a Stroke.

使用 DefaultDrawingAttributes 属性指定添加到 InkCanvas中的笔划的绘制属性。Use the DefaultDrawingAttributes property to specify the drawing attributes for the strokes added to an InkCanvas. 只有在 DefaultDrawingAttributes 进行更改后添加的笔划才会显示更新后的属性。Only strokes that are added after the DefaultDrawingAttributes undergo change show the updated attributes. InkCanvas 上已存在的笔画的外观不会改变。The appearance of the strokes that are already on the InkCanvas does not change.

有关 DrawingAttributes 类的实例的初始属性值列表,请参见 DrawingAttributes 构造函数。For a list of initial property values for an instance of the DrawingAttributes class, see the DrawingAttributes constructor.

XAML 文本用法XAML Text Usage

此类通常不在 XAML 中使用。This class is not typically used in XAML.

构造函数

DrawingAttributes()

初始化 DrawingAttributes 类的新实例。Initializes a new instance of the DrawingAttributes class.

字段

MaxHeight

指定 Height 属性所允许的最大值。Specifies the largest value allowed for the Height property.

MaxWidth

指定 Width 属性所允许的最大值。Specifies the largest value allowed for the Width property.

MinHeight

指定 Height 属性所允许的最小值。Specifies the smallest value allowed for the Height property.

MinWidth

指定 Width 属性所允许的最小值。Specifies the smallest value allowed for the Width property.

属性

Color

获取或设置 Stroke 的颜色。Gets or sets the color of a Stroke.

FitToCurve

获取或设置一个值,该值指示是否使用贝塞尔曲线平滑法来呈现 StrokeGets or sets a value that indicates whether Bezier smoothing is used to render the Stroke.

Height

获取或设置用于绘制 Stroke 的触笔的高度。Gets or sets the height of the stylus used to draw the Stroke.

IgnorePressure

获取或设置一个值,该值指示呈现的 Stroke 的粗细是否会随应用的压力而更改。Gets or sets a value that indicates whether the thickness of a rendered Stroke changes according the amount of pressure applied.

IsHighlighter

获取或设置一个值,该值指示 Stroke 看起来是否像一支荧光笔。Gets or sets a value that indicates whether the Stroke looks like a highlighter.

StylusTip

获取或设置用于绘制 Stroke 的触笔的形状。Gets or sets the shape of the stylus used to draw the Stroke.

StylusTipTransform

获取或设置 Matrix,它指定要在触笔笔尖上执行的变换。Gets or sets the Matrix that specifies the transformation to perform on the stylus' tip.

Width

获取或设置用于绘制 Stroke 的触笔的宽度。Gets or sets the width of the stylus used to draw the Stroke.

方法

AddPropertyData(Guid, Object)

将一个自定义属性添加到 DrawingAttributes 对象中。Adds a custom property to the DrawingAttributes object.

Clone()

复制 DrawingAttributes 对象。Copies the DrawingAttributes object.

ContainsPropertyData(Guid)

返回一个值,该值指示指定的属性数据标识符是否在 DrawingAttributes 对象中。Returns a value that indicates whether the specified property data identifier is in the DrawingAttributes object.

Equals(Object)

确定指定的 DrawingAttributes 对象是否等同于当前的 DrawingAttributesDetermines whether the specified DrawingAttributes object is equal to the current DrawingAttributes object.

GetHashCode()

用作特定类型的哈希函数。Serves as a hash function for a particular type.

GetPropertyData(Guid)

获取与指定 Guid 关联的自定义属性的值。Gets the value of the custom property associated with the specified Guid.

GetPropertyDataIds()

返回与 StrokeCollection 关联的任何自定义属性的 GUID。Returns the GUIDs of any custom properties associated with the StrokeCollection.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnAttributeChanged(PropertyDataChangedEventArgs)

引发 AttributeChanged 事件。Raises the AttributeChanged event.

OnPropertyChanged(PropertyChangedEventArgs)

当任何 DrawingAttributes 属性更改时发生。Occurs when any DrawingAttributes property changes.

OnPropertyDataChanged(PropertyDataChangedEventArgs)

引发 PropertyDataChanged 事件。Raises the PropertyDataChanged event.

RemovePropertyData(Guid)

移除与指定 Guid 关联的自定义属性。Removes the custom property associated with the specified Guid.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

运算符

Equality(DrawingAttributes, DrawingAttributes)

确定指定的 DrawingAttributes 对象是否相等。Determines whether the specified DrawingAttributes objects are equal.

Inequality(DrawingAttributes, DrawingAttributes)

确定指定的 DrawingAttributes 对象是否不相等。Determines whether the specified DrawingAttributes objects are not equal.

事件

AttributeChanged

当更改 DrawingAttributes 对象的属性时发生。Occurs when a property in the DrawingAttributes object changes.

PropertyDataChanged

在属性数据添加至 StrokeCollection 或从其中移除时发生。Occurs when property data is added or removed from the StrokeCollection.

显式接口实现

INotifyPropertyChanged.PropertyChanged

在任何 DrawingAttributes 属性的值更改时发生。Occurs when the value of any DrawingAttributes property has changed.

适用于