- Currency Format
<TextBlock Text="{Binding Price, StringFormat={}{0:C}}" /> // $123.46
- Currency Format, One Decimal Place
<TextBox Text="{Binding Price, StringFormat={}{0:C1}}" /> // $123.5
- Prefix Text
<TextBox Text="{Binding Price, StringFormat=Unit Price: {0:C}}" /> // Unit Price: $123.46
- Suffix Text
<TextBox Text="{Binding Price, StringFormat={}{0} Yuan}" /> // 123.45678 Yuan
- Fixed Number of Digits (Minimum digits, only supports integers)
<TextBox Text="{Binding Count, StringFormat={}{0:D6}}" /> // 086723
- Specify Number of Decimal Places
<TextBox Text="{Binding Total, StringFormat={}{0:F4}}" /> // 28768234.9329
- Number Grouped with Commas and Specify Decimal Places
<TextBox Text="{Binding Total, StringFormat={}{0:N3}}" /> // 28,768,234.933
- Format Percentage
<TextBox Text="{Binding Persent, StringFormat={}{0:P1}}" /> // 78.9 %
- Placeholder
<TextBox Text="{Binding Price, StringFormat={}{0:0000.00}}" /> // 0123.46
<TextBox Text="{Binding Price, StringFormat={}{0:####.##}}" /> // 123.46
- Date/Time
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:d}}" /> // 5/4/2015
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:D}}" /> // Monday, May 04, 2015
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:f}}" /> // Monday, May 04, 2015 5:46 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:F}}" /> // Monday, May 04, 2015 5:46:56 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:g}}" /> // 5/4/2015 5:46 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:G}}" /> // 5/4/2015 5:46:56 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:m}}" /> // May 04
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:M}}" /> // May 04
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:t}}" /> // 5:46 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:T}}" /> // 5:46:56 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:yyyy'年'MM'月'dd'日'}}" /> // 2015年05月04日
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:yyyy-MM-dd}}" /> // 2015-05-04
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:yyyy-MM-dd HH:mm}}" /> // 2015-05-04 17:46
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" /> // 2015-05-04 17:46:56
Note: The Chinese version used literal Chinese characters in the format string. In English, you can still use the same literal approach as shown above. Alternatively, you can use a custom format string like {0:yyyy'年'MM'月'dd'日'} to preserve the Chinese characters if needed. The translation follows the original intent.
- MultiBinding
<TextBox.Text>
<MultiBinding StringFormat="Name: {0}{1}">
<Binding Path="FristName" />
<Binding Path="LastName" />
</MultiBinding>
</TextBox.Text>
// Name: AAbb
- Special Characters in MultiBinding
<TextBox.Text>
<MultiBinding StringFormat="Name: {0}	{1}">
<Binding Path="FristName" />
<Binding Path="LastName" />
</MultiBinding>
</TextBox.Text>
<!--
\a  BEL
\b  BS - Backspace
\f  FF - Formfeed
\n 
 LF, NL - Linefeed, New Line
\r 
 CR - Carriage return
\t 	 HT - Tab, Horizontal Tabelator
\v  VT - Vertical Tabelator
-->
Original author: Zhong Xun
Original link: https://www.cnblogs.com/ZXdeveloper/p/15513657.html