DrawingAttributes.AddPropertyData(Guid, Object) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Ajoute une propriété personnalisée à l’objet 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)
Paramètres
- propertyData
- Object
Valeur de la propriété personnalisée.
propertyDatadoit être de type Char, , , ByteInt16UInt16Int32UInt32Int64UInt64SingleDoubleDateTime, Boolean, Stringou Decimal un tableau de ces types de données ; toutefois, il ne peut pas être un tableau de type .String
Exceptions
propertyData a la valeur null.
propertyDataId est vide Guid.
- ou -
propertyData n’est pas l’un des types de données autorisés répertoriés dans la Parameters section.
Exemples
L’exemple suivant montre comment ajouter et récupérer une propriété personnalisée à partir de l’objet DrawingAttributes . L’exemple ajoute une propriété qui indique si l’objet DrawingAttributes est un stylet ou un surligneur. Le code du ChangeColors_Click gestionnaire d’événements affiche une nouvelle couleur pour les traits sur l’objet InkCanvasDrawingAttributes. inkDA Cet exemple suppose qu’il existe un InkCanvas nom inkCanvas1et qu’il existe deux DrawingAttributes objets nommés inkDAet 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
Remarques
La AddPropertyData méthode vous permet d’ajouter des propriétés personnalisées à un DrawingAttributes objet. Cela est utile lorsque vous affichez vos propres traits et que vous souhaitez fournir des informations supplémentaires.