DrawingAttributes.ContainsPropertyData Method (Guid)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns a value that indicates whether the specified property data identifier is in the DrawingAttributes object.

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

public bool ContainsPropertyData(
	Guid propertyDataId


Type: System.Guid

The Guid to locate in the DrawingAttributes object .

Return Value

Type: System.Boolean

true if the specified property data identifier is in the DrawingAttributes object; otherwise, false.

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 ChangeColors_Click event handler changes all the strokes that were put on the InkCanvas with a DrawingAttributes called inkDA to a new color. 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