1

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.

4
  • It's probably a simple setting, but if you post the code that's autogenerated it will help us (well me) find the correct setting.
    – ChrisF
    Aug 7, 2010 at 21:03
  • I have no idea what you are asking. You mention a progress bar, a textblock, a "click", a slider, and a value. Where are each of these, and how do they relate to each other in your UI? What and where is "the value"? Aug 7, 2010 at 21:07
  • My best guess is that this might not actually have anything to do with WPF itself, and may just be "how do I format a string, if I am given a decimal". If this is the case, then please rephrase the question to remove any reference to WPF. Aug 7, 2010 at 21:08
  • Well I'm looking for a solution that might be in wpf so that I don't have to code each textblock manually to format the string
    – internetmw
    Aug 7, 2010 at 21:09

1 Answer 1

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.