語言

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必須是 型別 Char、 Byte、 Int16UInt16Int32UInt32Int64UInt64SingleDoubleDateTimeBooleanStringDecimal,或是這些資料型態的陣列,但 String不允許。

例外狀況

propertyDataId 是空的 Guid。

-或-

propertyData 並非本 Parameters 節所列允許的資料類型之一。

範例

以下範例示範如何新增並取得自訂屬性資料。 該AddTimeStamp_Click方法使用該AddPropertyData方法將當前時間加到。StrokeCollection 此 GetTimeStap_Click 方法使用該 GetPropertyData 方法從 中取得時間戳 StrokeCollection記。 此範例假設存在一個 InkCanvas 被呼叫 inkCanvas1的 。

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

適用於