2011-02-11 38 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}}"/>