WPF在XAML中Binding使用StringFormat屬性

一、綁定Currency,若是沒有字符的話,後面須要先加入{},不加的話會出問題html

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

二、綁定Currency,並在前面加入一些字符,跟上面相比,沒有{}spa

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

三、綁定日期.net

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

四、綁定時間code

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

五、多重綁定orm

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

六、多重綁定中的特殊字符,如 \txml

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


特殊字符以下:
\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 Tabelatorhtm

 

引用自:https://blog.csdn.net/jumtre/article/details/20624753blog

相關文章
相關標籤/搜索