简体   繁体   English

StringFormat轴标签

[英]StringFormat Axis Label

Where would I put my StringFormat={}{0:C} to make the axis label have currency formatting? 我将StringFormat = {} {0:C}放在哪里以使轴标签具有货币格式?

<DVC:LinearAxis Orientation="X" Interval="500000" ShowGridLines="True" Minimum="0" >
                                    <DVC:LinearAxis.AxisLabelStyle>
                                        <Style TargetType="DVC:AxisLabel">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="DVC:AxisLabel">
                                                        <TextBlock Text="{TemplateBinding FormattedContent}">
                                                            <TextBlock.LayoutTransform>
                                                                <RotateTransform Angle="60"/>
                                                            </TextBlock.LayoutTransform>
                                                        </TextBlock>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </DVC:LinearAxis.AxisLabelStyle>
                                </DVC:LinearAxis>

ContentStringFormat dont work anymore on SL4, this way worked for me, suggested by andulvar on sl forum : ContentStringFormat在SL4上不再起作用,这种方式对我有用 ,由andulvar在sl论坛上建议:

if you need only a StringFormat: 如果只需要一个StringFormat:

<TextBox DataContext="{TemplateBinding Value}" 
 Text="{Binding StringFormat='\{0:MM/dd HH:mm\} '}"/>

or if you want to use a Converter: 或者如果您想使用转换器:

<TextBox DataContext="{TemplateBinding Value}"
  Text="{Binding Converter={StaticResource Double2String}}"/>

I hope this way help someone, I spent a lot of time to find the right way to do this. 我希望这种方式可以帮助某人,我花了很多时间来找到正确的方法来做到这一点。

Even better, you can go ahead and put a customized text instead of just a number or a Date on a X, Y axis. 更好的是,您可以继续在X,Y轴上放置自定义的文本,而不只是数字或日期。 All you need is a Converter in between to translate a value (Number, Date) to a mush more meaningful text. 您所需要的只是一个介于两者之间的转换器,可将值(数字,日期)转换为糊糊的更有意义的文本。

<chartingToolkit:LinearAxis Orientation="X" ShowGridLines="True">
                <chartingToolkit:LinearAxis.AxisLabelStyle>
                    <Style TargetType="chartingToolkit:AxisLabel">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="chartingToolkit:AxisLabel">
                                    <TextBlock Text="{TemplateBinding FormattedContent, Converter={StaticResource MileTextConverter}}"></TextBlock>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </chartingToolkit:LinearAxis.AxisLabelStyle>
            </chartingToolkit:LinearAxis>

Not tested, but I think this will do the trick: 未经测试,但是我认为这可以解决问题:

<TextBlock Text="{TemplateBinding FormattedContent, StringFormat={}{0:C}}">

(It's the 7th line of your posted code.) (这是您发布的代码的第7行。)

<Label> 
   <Label.Content>
        <ContentPresenter Content="{TemplateBinding FormattedContent}" ContentStringFormat="{}{0:C}" />
    </Label.Content>
</Label>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM