我正在尝试有条件地格式化出现在 LineSeries 的 NumericAxis 轴中的数字(来自 Silverlight 4 Toolkit)。更具体地说,我希望 >=10000 和 <=0.0001 的数字以科学计数法显示,但我似乎无法完成这项工作。
我可以像这样覆盖 NumericAxisLabel 模板:
<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>
但这会将科学记数法格式应用于轴上的所有标签。我想要的是字符串格式表达式只有在我上面提到的条件发生时才“启动”。
通过使用带有自定义值转换器的绑定,我能够在 LineDataPoint 工具提示模板中轻松完成此操作,如下所示:
<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>
要是我能像在 LineDataPoint 模板中那样为 NumericAxisLabelStyle 中的“FormattedContent”指定一个转换器就好了……肯定有办法!
有任何想法吗?
在此先感谢您的帮助!