其他分享
首页 > 其他分享> > WPF中XAML中使用String.Format格式化字符串示例

WPF中XAML中使用String.Format格式化字符串示例

作者:互联网

WPF中XAML中使用String.Format格式化字符串示例

<TextBlock Text="{Binding Price, StringFormat={}{0:C}}" /> // $123.46
<TextBox Text="{Binding Price, StringFormat={}{0:C1}}" /> // $123.5
<TextBox Text="{Binding Price, StringFormat=单价:{0:C}}" /> //单价:$123.46
<TextBox Text="{Binding Price, StringFormat={}{0}元}" /> // 123.45678元
<TextBox Text="{Binding Count, StringFormat={}{0:D6}}" /> // 086723
<TextBox Text="{Binding Total, StringFormat={}{0:F4}}" /> // 28768234.9329
<TextBox Text="{Binding Total, StringFormat={}{0:N3}}" /> // 28,768,234.933
<TextBox Text="{Binding Persent, StringFormat={}{0:P1}}" /> // 78.9 %
<TextBox Text="{Binding Price, StringFormat={}{0:0000.00}}" /> // 0123.46
<TextBox Text="{Binding Price, StringFormat={}{0:####.##}}" /> // 123.46
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:d}}" /> // 5/4/2015
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:D}}" /> // Monday, May 04, 2015
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:f}}" /> // Monday, May 04, 2015 5:46 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:F}}" /> // Monday, May 04, 2015 5:46:56 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:g}}" /> // 5/4/2015 5:46 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:G}}" /> // 5/4/2015 5:46:56 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:m}}" /> // May 04
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:M}}" /> // May 04
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:t}}" /> // 5:46 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:T}}" /> // 5:46:56 PM
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:yyyy年MM月dd日}}" /> // 2015年05月04日
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:yyyy-MM-dd}}" /> // 2015-05-04
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:yyyy-MM-dd HH:mm}}" /> // 2015-05-04 17:46
<TextBox Text="{Binding DateTimeNow, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" /> // 2015-05-04 17:46:56
复制代码
<TextBox.Text>
    <MultiBinding StringFormat="姓名:{0}{1}">
         <Binding Path="FristName" />
         <Binding Path="LastName" />
    </MultiBinding>
 </TextBox.Text>
复制代码
// 姓名:AAbb
复制代码
<TextBox.Text>
     <MultiBinding StringFormat="姓名:{0}&#x09;{1}">
           <Binding Path="FristName" />
           <Binding Path="LastName" />
     </MultiBinding>
 </TextBox.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 
                        -->
复制代码  

标签:56,String,04,Format,46,示例,May,2015,PM
来源: https://www.cnblogs.com/gbnw/p/16668858.html