2011-02-11 62 views
1

我需要在XAML中使用字符串格式来格式化为数字,使得WPF字符串格式使用自定义分隔

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

当我写写

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

我最终得到:

12345678901 -> "12345678901.00000" 

对于实验,我尝试用空格替换点:

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

,并得到:

12345678901 -> "123456 78901" 

我想类似上例的行为,只能用一个“点” -speparator而不是“空间”。

任何人都知道如何使用XAML来做到这一点?

谢谢!

编辑:我只是想通,我需要逃跑的“点”,它经常被当作小数点:

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

你实在不应该使用视图来改变,这就是你在做什么,数据。 ViewModel应该提供正确形式的数据(如果不是最终格式)。 – Lazarus 2011-02-11 12:04:06

+0

ViewModel/Model的属性很长,在整个系统中用作数字。我宁愿不将它格式化为视图,然后在setter中解析它。 – 2011-02-11 12:14:19

回答

5

尝试像这样

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