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. 它也假設有一個稱為 switchHighlighterButton,而且 Click 事件會連接到此範例中定義的事件處理常式。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 物件是否等於目前的 DrawingAttributes 物件。Determines 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()

傳回代表目前物件的字串。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.

適用於