开发者

Format WPF progress bar decimals

开发者 https://www.devze.com 2023-01-11 02:35 出处:网络
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 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 fo开发者_高级运维r example.


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消