10-22-2012 04:12 AM
How do I change color of the point annotation label? I've found only properties for the shape stroke and fill.
Solved! Go to Solution.
10-22-2012 09:48 AM
Similar to Buttons and other ContentControls, you can customize the Label of an Annotation through the LabelTemplate property:
<ni:PointAnnotation Label="Annotaiton Label">
<ni:PointAnnotation.LabelTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="Green" />
</DataTemplate>
</ni:PointAnnotation.LabelTemplate>
</ni:PointAnnotation>
10-22-2012 10:05 AM
Ah, I see. Would you mind to write it down in code? I need to change it dynamically.
10-22-2012 10:39 AM
In that case, you want to use a model object for the label and bind the foreground in the data template as well as the text. As a simple example, here is how you can use an anonymous object as the label:
<ni:PointAnnotation x:Name="pointAnnotaiton">
<ni:PointAnnotation.LabelTemplate>
<DataTemplate>
<TextBlock Text="{Binding Text}" Foreground="{Binding Foreground}" />
</DataTemplate>
</ni:PointAnnotation.LabelTemplate>
</ni:PointAnnotation>
pointAnnotation.Label = new { Text = "Label", Foreground = Brushes.Green };
Normally, you would use a bindable object for the model, in which case you can change the foreground by updating just that property on the model. For this example, to update the foreground you create a new { Text, Foreground } anonymous object (which is a bit easier to show in a forum post :).
10-22-2012 12:50 PM
If I do
Label = new { Text = "annotation", Foreground = Brushes.Green }
then I see "Text = "annotation", Foreground = Brushes.Green" as a label
10-22-2012 01:51 PM
That looks like the ToString value of the object. Did you setup the LabelTemplate with the bindings shown in the previous XAML snippet?
If you need to assign the LabelTemplate from code as well, you can define it as a resource in the Resources for your page or application.
10-25-2012 03:02 AM
thanks!