Прочетете на английски Редактиране

Споделяне чрез


StrokeCollection.AddPropertyData(Guid, Object) Method

Definition

Adds a custom property to the StrokeCollection.

C#
public void AddPropertyData(Guid propertyDataId, object propertyData);

Parameters

propertyDataId
Guid

The Guid to associate with the custom property.

propertyData
Object

The value of the custom property. propertyData must be of type Char, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, DateTime, Boolean, String, Decimal or an array of these data types, except String, which is not allowed.

Exceptions

propertyDataId is an empty Guid.

-or-

propertyData is not one of the allowed data types listed in the Parameters section.

Examples

The following example demonstrates how to add and get custom property data. The AddTimeStamp_Click method uses the AddPropertyData method to add the current time to the StrokeCollection. The GetTimeStap_Click method uses the GetPropertyData method to retrieve the timestamp from the StrokeCollection. This example assumes that there is an InkCanvas called inkCanvas1.

C#
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.");
    }
}

Remarks

The AddPropertyData method enables you to add custom properties to a StrokeCollection. You can then include extra information with a StrokeCollection.

Applies to

Продукт Версии
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10