DrawingAttributes.GetPropertyData(Guid) Method

Definition

Gets the value of the custom property associated with the specified Guid.

public object GetPropertyData (Guid propertyDataId);

Parameters

propertyDataId
Guid

The Guid associated with the custom property to get.

Returns

The value of the custom property associated with the specified Guid.

Exceptions

propertyDataId is not associated with a custom property of the DrawingAttributes object.

Examples

The following example demonstrates how to add and retrieve a custom property from the DrawingAttributes object. The example adds a property that indicates whether the DrawingAttributes object is a pen or a highlighter. The code in the ChangeColors_Click event handler renders a new color for strokes on the InkCanvas that use the DrawingAttributes object, inkDA. This example assumes that there is an InkCanvas named inkCanvas1, and that there are two DrawingAttributes objects named inkDA, and highlighterDA.

Guid purposeGuid = new Guid("12345678-9012-3456-7890-123456789012");
string penValue = "pen";
string highlighterValue = "highlighter";

// Add a property to each DrawingAttributes object to 
// specify its use.
private void AssignDrawingAttributesInstrument()
{
    inkDA.AddPropertyData(purposeGuid, penValue);
    highlighterDA.AddPropertyData(purposeGuid, highlighterValue);
}

// Change the color of the ink that on the InkCanvas that used the pen.
void ChangeColors_Click(Object sender, RoutedEventArgs e)
{
    foreach (Stroke s in inkCanvas1.Strokes)
    {
        if (s.DrawingAttributes.ContainsPropertyData(purposeGuid))
        {
            object data = s.DrawingAttributes.GetPropertyData(purposeGuid);

            if ((data is string) && ((string)data == penValue))
            {
                s.DrawingAttributes.Color = Colors.Black;
            }
        }
    }
}

Remarks

Use the GetPropertyData method to access custom properties you added to a DrawingAttributes object. GetPropertyData returns the default value for the built-in property if a value has not been set.

Applies to

Producto Versiones
.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

See also