其他分享
首页 > 其他分享> > WPF中Binding使用StringFormat格式化字符串方法

WPF中Binding使用StringFormat格式化字符串方法

作者:互联网

 

 转自:https://www.cnblogs.com/xuliming/articles/StringFormat.html
<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 
                        -->
复制代码 // 姓名:AA    bb

标签:04,05,46,Binding,StringFormat,May,2015,WPF,PM
来源: https://www.cnblogs.com/robertyao/p/11727300.html