I am trying to conditionally format the numbers that appear in a NumericAxis axis for a LineSeries (from Silverlight 4 Toolkit). To be more specific, I want numbers that are >=10000 and <=0.0001 to display in scientific notation, but I can't seem to make this work.
I can override the NumericAxisLabel template like this:
<Style x:Key="NumericAxisLabelStyle" TargetType="chartingToolkit:NumericAxisLabel">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="StringFormat" Value="{}{0:0.0E+00}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="chartingToolkit:NumericAxisLabel">
<TextBlock Text="{TemplateBinding FormattedContent}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
But this will apply the scientific notation format to ALL labels in the axis. What I want is for the string format expression to "kick in" only when the condition I mentioned above occurs.
I was able to accomplish this in the LineDataPoint tooltip template fairly easy by using a binding with a custom value converter, like this:
<ControlTemplate TargetType="chartingToolkit:LineDataPoint">
<Grid x:Name="Root" Opacity="0">
<ToolTipService.ToolTip>
<StackPanel Margin="2,2,2,2">
<StackPanel Orientation="Horizontal">
<TextBlock Text="X:" />
<ContentControl Content="{Binding objResultValueX, Converter={StaticResource ToCustomStringFormat}}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Y:" />
<ContentControl Content="{Binding dblResultValueY, Converter={StaticResource ToCustomStringFormat}}"/>
</StackPanel>
</StackPanel>
</ToolTipService.ToolTip>
...
</Grid>
</ControlTemplate>
If only I could specify a converter for the "FormattedContent" in the NumericAxisLabelStyle like I do for LineDataPoint template...surely there must be a way!
Any ideas?
Thanks in advance for the help!
Try setting the DataContext of the TextBlock to FormattedContent. Then apply the converter to the Text property as so:
<Style x:Key="NumericAxisLabelStyle" TargetType="chartingToolkit:NumericAxisLabel">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value >
<ControlTemplate TargetType="chartingToolkit:NumericAxisLabel">
<TextBlock DataContext="{TemplateBinding FormattedContent}" Text ="{Binding Converter={StaticResource ToCustomStringFormat}}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>