DrawingAttributes.GetPropertyData Method (Guid)

 

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

Namespace:   System.Windows.Ink
Assembly:  PresentationCore (in PresentationCore.dll)

public object GetPropertyData(
	Guid propertyDataId
)

Parameters

propertyDataId
Type: System.Guid

The Guid associated with the custom property to get.

Return Value

Type: System.Object

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

Exception Condition
ArgumentException

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

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.

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;
            }
        }
    }
}

.NET Framework
Available since 3.0
Return to top
Show: