internetmw
internetmw

Reputation: 699

Format WPF progress bar decimals

I have a progressbar in WPF C# and I bind the text of a textblock to the value of WPF. All in one click, it's great. However, when sliding the slider, the value changes to many many decimals. How can I format this value to have for example 2 numbers behind comma?

UPDATE: The request

<Slider x:Name="eqbandwidth" Margin="164.122,111.813,122.564,0" VerticalAlignment="Top" Minimum="1" Maximum="36" Value="12"/><TextBlock HorizontalAlignment="Right" Margin="0,95.399,143.134,0" TextWrapping="Wrap" Text="{Binding Value, ElementName=eqbandwidth}" VerticalAlignment="Top" Foreground="#FFB6B6B6" FontSize="9.333" TextAlignment="Center"/>

results in a value like: 24.656702025072359

To make my question more clear: I want the values to be 24.67 for example.

Upvotes: 1

Views: 1203

Answers (1)

Femaref
Femaref

Reputation: 61457

<TextBlock [...] 
           Text="{Binding Value, ElementName=eqbandwidth, StringFormat=N2}" 
           [...] />

StringFormat exists since .net 3.0 I think, it takes a normal string formatting string.

Upvotes: 1

Related Questions