Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XAML StringFormat to format a Double value

Tags:

c#

wpf

xaml

I want to format my slider value to be 00:00 format. The below code worked for me, but what I wanted is 00:00 format. I am looking for a total XAML solution. I know that I can write a converter for this easily but wonder if there are any StringFormat way to make it.

Text="{Binding Value, ElementName=slider,StringFormat=\{0:00.00\}}" 

My question here is how can I get colon ':' instead of dot '.' ?

like image 593
Jobi Joy Avatar asked Jul 29 '09 17:07

Jobi Joy


2 Answers

If you just want to put a : symbol in the format string, then you escape it with backslashes:

Text="{Binding Value, ElementName=slider,StringFormat=\{0:00\\:00\}}"

But I think this is what you want to do:

<Slider Name="slider" Width="500" Height="30" Maximum="100" Minimum="0" />
<TextBlock Text="{Binding Path=Value, ElementName=slider, StringFormat={}{0:00\\:00}}" />
like image 160
Nate Zaugg Avatar answered Sep 24 '22 02:09

Nate Zaugg


You can use the default String formatting options in the StringFormat as in regular C# code. Have a look at this page, you'll probably find what you need.

like image 28
user112889 Avatar answered Sep 26 '22 02:09

user112889