DrawingAttributes.GetPropertyData(Guid) 方法

定义

获取与指定 Guid 关联的自定义属性的值。

public:
 System::Object ^ GetPropertyData(Guid propertyDataId);
public object GetPropertyData (Guid propertyDataId);
member this.GetPropertyData : Guid -> obj
Public Function GetPropertyData (propertyDataId As Guid) As Object

参数

propertyDataId
Guid

与要获取的自定义属性关联的 Guid

返回

Object

与指定 Guid 关联的自定义属性的值。

例外

propertyDataId 不与 DrawingAttributes 对象的自定义属性关联。

示例

以下示例演示如何从 DrawingAttributes 对象中添加和检索自定义属性。 该示例添加一个属性,该属性指示对象是笔还是 DrawingAttributes 荧光笔。 事件处理程序中的ChangeColors_Click代码为使用该DrawingAttributes对象的inkDA笔划InkCanvas呈现新的颜色。 此示例假定有一个命名inkCanvas1对象,并且有两DrawingAttributesInkCanvas命名inkDA对象,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;
            }
        }
    }
}
Private purposeGuid As New Guid("12345678-9012-3456-7890-123456789012")
Private penValue As String = "pen"
Private highlighterValue As String = "highlighter"

' Add a property to each DrawingAttributes object to 
' specify its use.
Private Sub AssignDrawingAttributesInstrument()

    inkDA.AddPropertyData(purposeGuid, penValue)
    highlighterDA.AddPropertyData(purposeGuid, highlighterValue)

End Sub

' Change the color of the ink that on the InkCanvas that used the pen.
Private Sub ChangeColors_Click(ByVal sender As [Object], _
        ByVal e As RoutedEventArgs)

    Dim s As Stroke

    For Each s In inkCanvas1.Strokes
        If s.DrawingAttributes.ContainsPropertyData(purposeGuid) Then

            Dim data As Object = s.DrawingAttributes.GetPropertyData(purposeGuid)

            If TypeOf data Is String AndAlso CStr(data) = penValue Then
                s.DrawingAttributes.Color = Colors.Black
            End If

        End If
    Next s

End Sub

注解

使用此方法 GetPropertyData 访问添加到 DrawingAttributes 对象的自定义属性。 GetPropertyData 如果未设置值,则返回内置属性的默认值。

适用于

另请参阅