DrawingAttributes.GetPropertyData(Guid) Metodo

Definizione

Ottiene il valore della proprietà personalizzata associata all'oggetto Guid specificato.

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

Parametri

propertyDataId
Guid

Oggetto Guid associato alla proprietà personalizzata da ottenere.

Restituisce

Object

Valore della proprietà personalizzata associata all'oggetto Guid specificato.

Eccezioni

L'oggetto propertyDataId non è associato a una proprietà personalizzata dell'oggetto DrawingAttributes.

Esempio

Nell'esempio seguente viene illustrato come aggiungere e recuperare una proprietà personalizzata dall'oggetto DrawingAttributes . Nell'esempio viene aggiunta una proprietà che indica se l'oggetto DrawingAttributes è una penna o un evidenziatore. Il codice nel ChangeColors_Click gestore eventi esegue il rendering di un nuovo colore per i tratti sull'oggetto InkCanvas che utilizzano l'oggetto DrawingAttributes . inkDA In questo esempio si presuppone che sia presente un InkCanvas oggetto denominato inkCanvas1e che siano presenti due DrawingAttributes oggetti denominati inkDA, e 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

Commenti

Usare il GetPropertyData metodo per accedere alle proprietà personalizzate aggiunte a un DrawingAttributes oggetto. GetPropertyData restituisce il valore predefinito per la proprietà predefinita se un valore non è stato impostato.

Si applica a

Vedi anche