1

I need to format a number using String Format in XAML such that

 12345678901 -> "123456.78901"
  2345678901 -> "023456.78901" 

When I write write

<TextBox Text="{Binding TheNumber, StringFormat={}{0:000000.00000}}"/>

I end up getting:

12345678901 -> "12345678901.00000"

For experimentation, I try replacing the dot with a space:

<TextBox Text="{Binding TheNumber, StringFormat={}{0:000000 00000}}"/>

and get:

12345678901 -> "123456 78901"

I would like a behavior similar to the last example, only with a "dot"-speparator instead of "space".

Anyone know how to do this using XAML only?

Thanks!

Edit: I just figured that I need to escape the "dot", which regularly is treated as a decimal point:

<TextBox Text="{Binding TheNumber, StringFormat={}{0:000000\\.00000}}"/>
3
  • You shouldn't really be using the View to alter, and that's what you are doing, the data. The ViewModel should be providing the data with the correct form (if not the final format). Commented Feb 11, 2011 at 12:04
  • The ViewModel/Model's property is a long, which is used as a number throughout the system. I'd rather not format it for the view and then parse it in the setter. Commented Feb 11, 2011 at 12:14
  • Why not use a converter? Commented Feb 11, 2011 at 12:25

1 Answer 1

6

Try it like this

<TextBox Text="{Binding TheNumber, StringFormat={}{0:000000'.'00000}}"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.