StrokeCollection.AddPropertyData(Guid, Object) 方法

定義

將自訂屬性加入至 StrokeCollection

public:
 void AddPropertyData(Guid propertyDataId, System::Object ^ propertyData);
public void AddPropertyData (Guid propertyDataId, object propertyData);
member this.AddPropertyData : Guid * obj -> unit
Public Sub AddPropertyData (propertyDataId As Guid, propertyData As Object)

參數

propertyDataId
Guid

與自訂屬性建立關聯的 Guid

propertyData
Object

自訂屬性的值。 propertyData 必須屬於 CharByteInt16UInt16Int32UInt32Int64UInt64SingleDoubleDateTimeBooleanStringDecimal 類型或這些資料類型的陣列,但不包含不允許的 String

例外狀況

propertyDataId 為空的 Guid

-或-

propertyData 不屬於 Parameters 一節中列出的其中一種允許資料型別。

範例

下列範例示範如何新增和取得自訂屬性資料。 方法 AddTimeStamp_ClickAddPropertyData 使用 方法,將目前時間新增至 StrokeCollection 。 方法 GetTimeStap_ClickGetPropertyData 使用 方法從 StrokeCollection 擷取時間戳記。 此範例假設有一個名為 InkCanvasinkCanvas1 的 。

Guid timestamp = new Guid("12345678-9012-3456-7890-123456789012");

// Add a timestamp to the StrokeCollection.
private void AddTimestamp_Click(object sender, RoutedEventArgs e)
{

    inkCanvas1.Strokes.AddPropertyData(timestamp, DateTime.Now);
}

// Get the timestamp of the StrokeCollection.
private void GetTimestamp_Click(object sender, RoutedEventArgs e)
{

    if (inkCanvas1.Strokes.ContainsPropertyData(timestamp))
    {
        object date = inkCanvas1.Strokes.GetPropertyData(timestamp);

        if (date is DateTime)
        {
            MessageBox.Show("This StrokeCollection's timestamp is " +
                ((DateTime)date).ToString());
        }
    }
    else
    {
        MessageBox.Show(
            "The StrokeCollection does not have a timestamp.");
    }
}
Private timestamp As New Guid("12345678-9012-3456-7890-123456789012")

' Add a timestamp to the StrokeCollection.
Private Sub AddTimestamp_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

    inkCanvas1.Strokes.AddPropertyData(timestamp, DateTime.Now)

End Sub

' Get the timestamp of the StrokeCollection.
Private Sub GetTimestamp_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

    If inkCanvas1.Strokes.ContainsPropertyData(timestamp) Then

        Dim savedDate As Object = inkCanvas1.Strokes.GetPropertyData(timestamp)

        If TypeOf savedDate Is DateTime Then
            MessageBox.Show("This StrokeCollection's timestamp is " & _
                CType(savedDate, DateTime).ToString())
        End If
    Else
        MessageBox.Show("The StrokeCollection does not have a timestamp.")
    End If

End Sub

備註

方法 AddPropertyData 可讓您將自訂屬性新增至 StrokeCollection 。 接著,您可以使用 包含額外的資訊 StrokeCollection

適用於