WPF StringFormat used in XAML Binding Properties

1. Binding Currency, if no characters, need to join behind = {} then go wrong without.

1
<TextBlock Text= "{Binding Amount, StringFormat={}{0:C}}" />

2. Binding Currency, and add some character before. 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

1
<TextBlock Text= "{Binding Date, StringFormat={}{0:MM/dd/yyyy hh:mm tt}}" />

5. Multiple Binding

1
2
3
4
5
6
<TextBlock.Text>
     <MultiBinding StringFormat= "Delete {0} {1}" >
         <Binding Path= "FirstName" />
         <Binding Path= "LastName" />
     </MultiBinding>
  </TextBlock.Text>

6. Multiple bindings special characters, such as \ t

1
2
3
4
5
6
<TextBlock.Text>
     <MultiBinding StringFormat= "Delete {0}&#x09;{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

Transfer from: http: //blog.jinlook.com/post/2012/07/23/XAMLBindingStringFormat.aspx

 

Reproduced in: https: //my.oschina.net/garyun/blog/602721

Guess you like

Origin blog.csdn.net/weixin_34409703/article/details/91774591