DrawingAttributes.AddPropertyData(Guid, Object) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Adiciona uma propriedade personalizada ao DrawingAttributes objeto.
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
- propertyData
- Object
O valor da propriedade personalizada.
propertyDatadeve ser do tipo Char, Byte, Int16UInt16, Int32, UInt32, Int64, , UInt64, SingleDoubleDateTimeBooleanStringou Decimal um array destes tipos de dados; no entanto, não pode ser um array do tipo .String
Exceções
propertyData é null.
propertyDataId é um vazio Guid.
-ou-
propertyData não é um dos tipos de dados permitidos listados na Parameters secção.
Exemplos
O exemplo seguinte demonstra como adicionar e recuperar uma propriedade personalizada do DrawingAttributes objeto. O exemplo acrescenta uma propriedade que indica se o DrawingAttributes objeto é uma caneta ou um marcador. O código no ChangeColors_Click gestor de eventos renderiza uma nova cor para traços nos InkCanvas que utilizam o DrawingAttributes objeto, inkDA. Este exemplo assume que existe um InkCanvas nome inkCanvas1, e que existem dois DrawingAttributes objetos nomeados 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
Observações
O AddPropertyData método permite-lhe adicionar propriedades personalizadas a um DrawingAttributes objeto. Isto é útil quando renderizas os teus próprios traços e queres fornecer informação extra.