Compartir a través de


DrawingAttributes.AddPropertyData(Guid, Object) Método

Definición

Agrega una propiedad personalizada al objeto 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)

Parámetros

propertyDataId
Guid

Guid que se va a asociar a la propiedad personalizada.

propertyData
Object

Valor de la propiedad personalizada. propertyData debe ser de tipo Char, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, DateTime, Boolean, String, Decimal o una matriz de estos tipos de datos; sin embargo, no puede ser una matriz de tipo String.

Excepciones

propertyData es null.

propertyDataId es un Guid vacío.

O bien propertyData no es ninguno de los tipos de datos permitidos que se muestran en la sección Parameters.

Ejemplos

En el ejemplo siguiente se muestra cómo agregar y recuperar una propiedad personalizada del DrawingAttributes objeto . En el ejemplo se agrega una propiedad que indica si el DrawingAttributes objeto es un lápiz o un resaltador. El código del ChangeColors_Click controlador de eventos representa un nuevo color para los trazos en que InkCanvas usan el DrawingAttributes objeto , inkDA. En este ejemplo se supone que hay un InkCanvas denominado inkCanvas1y que hay dos DrawingAttributes objetos denominados inkDA, y 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

Comentarios

El AddPropertyData método permite agregar propiedades personalizadas a un DrawingAttributes objeto . Esto resulta útil cuando se representan sus propios trazos y se desea proporcionar información adicional.

Se aplica a