Sdílet prostřednictvím


DrawingAttributes.AddPropertyData(Guid, Object) Metoda

Definice

Přidá do objektu DrawingAttributes vlastní vlastnost.

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)

Parametry

propertyDataId
Guid

Chcete-li Guid přidružit k vlastní vlastnosti.

propertyData
Object

Hodnota vlastní vlastnosti. propertyDatamusí být typu Char, , , Int16UInt16, Int32, UInt32, Int64, UInt64, DateTimeSingleDoubleBooleanStringDecimal nebo pole těchto datových typů, ale nemůže se jednat o pole typu .StringByte

Výjimky

propertyData je null.

propertyDataId je prázdný Guid.

-nebo-

propertyData není jedním z povolených datových typů uvedených v části Parameters .

Příklady

Následující příklad ukazuje, jak přidat a načíst vlastní vlastnost z objektu DrawingAttributes . Příklad přidá vlastnost, která označuje, zda DrawingAttributes je objekt perem nebo zvýrazňovačem. Kód v obslužné rutině ChangeColors_Click události vykreslí novou barvu pro tahy na objektu InkCanvas , inkDAkterý používá DrawingAttributes objekt . V tomto příkladu se předpokládá, že existuje InkCanvas objekt s názvem inkCanvas1, a že existují dva DrawingAttributes objekty s názvem inkDA, a 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

Poznámky

Metoda AddPropertyData umožňuje přidat do objektu DrawingAttributes vlastní vlastnosti. To je užitečné, když vykreslujete vlastní tahy a chcete poskytnout další informace.

Platí pro