Verint Verint
Verint Verint

Reputation: 567

Use XAML StringFormat to get one decimal place

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 ?

Upvotes: 1

Views: 7501

Answers (1)

Maxime Tremblay-Savard
Maxime Tremblay-Savard

Reputation: 967

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" />

Upvotes: 2

Related Questions