1. Bind currency, if there is no character, = next need to first join {}. There will be problems if not added.
1 |
<TextBlock Text= "{Binding Amount, StringFormat={}{0:C}}" /> |
2. Bind the currency and add some characters to the front. Compared with the above, there is no {}
1 |
<TextBlock Text= "{Binding Amount, StringFormat=Total: {0:C}}" /> |
3. Binding Date
1 |
<TextBlock Text= "{Binding Date, StringFormat={}{0:MM/dd/yyyy}}" /> |
4. Binding time between
1 |
<TextBlock Text= "{Binding Date, StringFormat={}{0:MM/dd/yyyy hh:mm tt}}" /> |
5. Multiple bindings
123456 |
<TextBlock.Text> <MultiBinding StringFormat= "Delete {0} {1}" > <Binding Path= "FirstName" /> <Binding Path= "LastName" /> </MultiBinding> </TextBlock.Text> |
6. Special characters in multiple bindings, such as \ t
123456 |
<TextBlock.Text> <MultiBinding StringFormat= "Delete {0}	{1}" > <Binding Path= "FirstName" /> <Binding Path= "LastName" /> </MultiBinding> </TextBlock.Text> |
Special characters are as follows:
- \a & #x07; BEL
- \b & #x08; Bs-backspace
- \f & #x0c; Ff-formfeed
- \ n & #x0a; LF, Nl-linefeed, New Line
- \ R & #x0d; Cr-carriage return
- \ t & #x09; Ht-tab, Horizontal Tabelator
- \v & #x0b; Vt-vertical Tabelator
Transferred from: http://blog.jinlook.com/post/2012/07/23/XAMLBindingStringFormat.aspx
WPF binding in XAML uses the StringFormat property