WPF binding in XAML uses the StringFormat property

Source: Internet
Author: User

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}&#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

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

WPF binding in XAML uses the StringFormat property

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.