StrokeCollection.AddPropertyData(Guid, Object) Méthode

Définition

Ajoute une propriété personnalisée à StrokeCollection ;

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)

Paramètres

propertyDataId
Guid

Guid à associer à la propriété personnalisée.

propertyData
Object

Valeur de la propriété personnalisée. propertyData doit être de type Char, Byte,Int16,UInt16, Int32, UInt32, Int64, UInt64, Single, Double, DateTime, Boolean, String, Decimal ou un tableau de ces types de données, à l’exception de String, qui n’est pas autorisé.

Exceptions

propertyDataId est un Guid vide.

  • ou - propertyData n'est pas un des types de données autorisé répertorié dans la section Parameters.

Exemples

L’exemple suivant montre comment ajouter et obtenir des données de propriété personnalisées. La AddTimeStamp_Click méthode utilise la AddPropertyData méthode pour ajouter l’heure actuelle au StrokeCollection. La GetTimeStap_Click méthode utilise la GetPropertyData méthode pour récupérer l’horodatage à partir du StrokeCollection. Cet exemple suppose qu’il existe un InkCanvas appelé inkCanvas1.

Guid timestamp = new Guid("12345678-9012-3456-7890-123456789012");

// Add a timestamp to the StrokeCollection.
private void AddTimestamp_Click(object sender, RoutedEventArgs e)
{

    inkCanvas1.Strokes.AddPropertyData(timestamp, DateTime.Now);
}

// Get the timestamp of the StrokeCollection.
private void GetTimestamp_Click(object sender, RoutedEventArgs e)
{

    if (inkCanvas1.Strokes.ContainsPropertyData(timestamp))
    {
        object date = inkCanvas1.Strokes.GetPropertyData(timestamp);

        if (date is DateTime)
        {
            MessageBox.Show("This StrokeCollection's timestamp is " +
                ((DateTime)date).ToString());
        }
    }
    else
    {
        MessageBox.Show(
            "The StrokeCollection does not have a timestamp.");
    }
}
Private timestamp As New Guid("12345678-9012-3456-7890-123456789012")

' Add a timestamp to the StrokeCollection.
Private Sub AddTimestamp_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

    inkCanvas1.Strokes.AddPropertyData(timestamp, DateTime.Now)

End Sub

' Get the timestamp of the StrokeCollection.
Private Sub GetTimestamp_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

    If inkCanvas1.Strokes.ContainsPropertyData(timestamp) Then

        Dim savedDate As Object = inkCanvas1.Strokes.GetPropertyData(timestamp)

        If TypeOf savedDate Is DateTime Then
            MessageBox.Show("This StrokeCollection's timestamp is " & _
                CType(savedDate, DateTime).ToString())
        End If
    Else
        MessageBox.Show("The StrokeCollection does not have a timestamp.")
    End If

End Sub

Remarques

La AddPropertyData méthode vous permet d’ajouter des propriétés personnalisées à un StrokeCollection. Vous pouvez ensuite inclure des informations supplémentaires avec un StrokeCollection.

S’applique à