WPF在XAML中Binding使用StringFormat屬性

來源:互聯網
上載者:User

標籤:

1. 綁定Currency, 如果沒有字元的話, =後面需要先加入{}. 不加的話會出問題.

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

2. 綁定Currency,並在前面加入一些字元. 跟上面相比, 沒有{}

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

3. 綁定日期

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

4. 綁定時間

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

5. 多重綁定

123456 <TextBlock.Text>    <MultiBinding StringFormat="Delete {0} {1}">        <Binding Path="FirstName" />        <Binding Path="LastName" />    </MultiBinding> </TextBlock.Text>

6. 多重綁定中的特殊字元, 如 \t

123456 <TextBlock.Text>    <MultiBinding StringFormat="Delete {0}&#x09;{1}">        <Binding Path="FirstName" />        <Binding Path="LastName" />    </MultiBinding> </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 Tabelator

轉自:http://blog.jinlook.com/post/2012/07/23/XAMLBindingStringFormat.aspx

 

WPF在XAML中Binding使用StringFormat屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.