DrawingAttributes.AddPropertyData(Guid, Object) 메서드

정의

개체에 사용자 지정 속성을 DrawingAttributes 추가합니다.

public:
 void AddPropertyData(Guid propertyDataId, System::Object ^ propertyData);
public void AddPropertyData(Guid propertyDataId, object propertyData);
member this.AddPropertyData : Guid * obj -> unit
Public Sub AddPropertyData (propertyDataId As Guid, propertyData As Object)

매개 변수

propertyDataId
Guid

Guid 사용자 지정 속성과 연결할 개체입니다.

propertyData
Object

사용자 지정 속성의 값입니다. propertyData는 이러한 데이터 형식의 배열Char, , ByteInt16, UInt16, Int32, UInt32Int64, UInt64SingleDoubleDateTimeBooleanStringDecimal 또는 이러한 데이터 형식의 배열이어야 하지만 형식String의 배열일 수는 없습니다.

예외

propertyDatanull입니다.

propertyDataId 가 비어 Guid있습니다.

-또는-

propertyData 은 섹션에 나열된 허용된 Parameters 데이터 형식 중 하나가 아닙니다.

예제

다음 예제에서는 개체에서 DrawingAttributes 사용자 지정 속성을 추가하고 검색하는 방법을 보여 줍니다. 다음은 개체가 펜인지 형광펜인지 여부를 DrawingAttributes 나타내는 속성을 추가하는 예제입니다. 이벤트 처리기의 코드 ChangeColors_Click 는 개체를 사용하는 스트로크에 InkCanvas 대한 새 색을 DrawingAttributes 렌더링합니다 inkDA. 이 예제에서는 명명된 InkCanvas 개체 inkCanvas1가 있고 두 개의 DrawingAttributes 개체가 있다고 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

설명

AddPropertyData 메서드를 사용하면 개체에 사용자 지정 속성을 추가할 수 있습니다 DrawingAttributes . 이 기능은 고유한 스트로크를 렌더링하고 추가 정보를 제공하려는 경우에 유용합니다.

적용 대상