Use XAML StringFormat to get one decimal place

7.1k views Asked by At

I have this Circle Slider:

enter image description here

And this is my TextBlock inside:

        <TextBlock Text="{Binding Path=Value, ElementName=knobSlider}" Foreground="White"
                   FontFamily="Trebuchet MS" FontSize="20" HorizontalAlignment="Center"
                   VerticalAlignment="Center" RenderTransformOrigin="0.7,2.478" Margin="59,100,44,26" Width="47" />

How can i convert the Slider value from double to only one decimal place and put this text in the middle of the circle ?

1

There are 1 answers

2
Maxime Tremblay-Savard On BEST ANSWER

Simply use the string format <TextBox Text="{Binding Value, StringFormat={}{0:#,#.0}}" />.

So in your case it would look like:

<TextBlock Text="{Binding Path=Value, ElementName=knobSlider, StringFormat={}{0:#,#.0}}" Foreground="White"
               FontFamily="Trebuchet MS" FontSize="20" HorizontalAlignment="Center"
               VerticalAlignment="Center" RenderTransformOrigin="0.7,2.478" Margin="59,100,44,26" Width="47" />