DrawingAttributes 類別

定義

指定 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 上使用畫筆和醒目提示器。 此範例假設 XAML 檔案中的根項目稱為 DockPanelroot 。 它也會假設有一個 Button 呼叫 switchHighlighter ,而且事件 Click 已連線到此範例中所定義的事件處理常式。

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 的形狀。

DefaultDrawingAttributes使用 屬性可指定加入至 InkCanvas 之筆劃的繪圖屬性。 只有經過變更之後新增的 DefaultDrawingAttributes 筆劃會顯示更新的屬性。 已經位於 上的 InkCanvas 筆劃外觀不會變更。

如需 DrawingAttributes 類別之執行個體的初始屬性值清單,請參閱 DrawingAttributes 建構函式。

XAML 文字使用方式

這個類別通常不會在 XAML 中使用。

建構函式

DrawingAttributes()

初始化 DrawingAttributes 類別的新執行個體。

欄位

MaxHeight

指定 Height 屬性允許的最大值。

MaxWidth

指定 Width 屬性允許的最大值。

MinHeight

指定 Height 屬性允許的最小值。

MinWidth

指定 Width 屬性允許的最小值。

屬性

Color

取得或設定 Stroke 的色彩。

FitToCurve

取得或設定值,這個值指出是否使用貝茲平滑化來呈現 Stroke

Height

取得或設定用來繪製 Stroke 的手寫筆高度。

IgnorePressure

取得或設定值,這個值指出呈現的 Stroke 粗細是否會隨著套用的壓力總量變更。

IsHighlighter

取得或設定值,這個值指出 Stroke 看起來是否像螢光筆。

StylusTip

取得或設定用來繪製 Stroke 的手寫筆圖案。

StylusTipTransform

取得或設定 Matrix,這個值指定要執行於手寫筆筆尖的透明度。

Width

取得或設定用來繪製 Stroke 的手寫筆寬度。

方法

AddPropertyData(Guid, Object)

將自訂屬性加入至 DrawingAttributes 物件。

Clone()

複製 DrawingAttributes 物件。

ContainsPropertyData(Guid)

傳回值,指出指定的屬性資料識別碼是否在 DrawingAttributes 物件中。

Equals(Object)

判斷指定的 DrawingAttributes 物件是否等於目前的 DrawingAttributes 物件。

GetHashCode()

以特定類型的雜湊函式進行服務。

GetPropertyData(Guid)

取得與指定 Guid 關聯的自訂屬性值。

GetPropertyDataIds()

傳回 StrokeCollection 關聯之任何自訂屬性的 GUID。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnAttributeChanged(PropertyDataChangedEventArgs)

引發 AttributeChanged 事件。

OnPropertyChanged(PropertyChangedEventArgs)

在任何 DrawingAttributes 屬性變更時發生。

OnPropertyDataChanged(PropertyDataChangedEventArgs)

引發 PropertyDataChanged 事件。

RemovePropertyData(Guid)

移除與指定 Guid 關聯的自訂屬性。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

運算子

Equality(DrawingAttributes, DrawingAttributes)

判斷指定的 DrawingAttributes 物件是否相等。

Inequality(DrawingAttributes, DrawingAttributes)

判斷指定的 DrawingAttributes 物件是否不相等。

事件

AttributeChanged

DrawingAttributes 物件中的屬性變更時發生。

PropertyDataChanged

發生於當屬性資料加入至 StrokeCollection 或從中移除時。

明確介面實作

INotifyPropertyChanged.PropertyChanged

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

任何 DrawingAttributes 屬性的值變更時發生。

適用於