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} {1}">
<Binding Path="FristName" />
<Binding Path="LastName" />
</MultiBinding>
</TextBox.Text>
<!--
\a  BEL
\b  BS - Backspace
\f  FF - Formfeed
\n LF, NL - Linefeed, New Line
\r CR - Carriage return
\t HT - Tab, Horizontal Tabelator
\v  VT - Vertical Tabelator
-->
WPF中XAML中使用String.Format格式化字符串示例的更多相关文章
- string.format格式化字符串中转义大括号“{}”
今天,用Java读取配置文件占位符,使用String.Format(string format,object arg0)方法.以前只知“{0}”为索引占位符(即格式项),与参数列表中的第一个对象相对应 ...
- java中实现与.net的format格式化字符串输出
Java中的格式化字符串 System.out.println(MessageFormat.format("name={0}", "张三")); .net中的格 ...
- String.format() 格式化字符串
1.几种常见的转换符 转换符 说明 实例 %d 整数类型(十进制) 99 %f 浮点类型 99.99 %s 字符串类型 "mingrisoft" %c 字符类型 'm' %b 布尔 ...
- C# String.Format 格式化字符串 数字/时间
首先献给只想知道结果的人 格式化 DateTime 对象 标准 数字 格式化 Int Decimal Float Double 关于这一块一直不是很清楚,MSDN 上也不够清晰. 就花了点时间敲了一下 ...
- 【C#】WPF的xaml中定义的Trigger为什么有时候会不管用,如Border的MouseOver之类的
原文:[C#]WPF的xaml中定义的Trigger为什么有时候会不管用,如Border的MouseOver之类的 初学WPF,知道一些控件可以通过定义Style的Trigger改变要显示的样式,但是 ...
- 整理:WPF中Xaml中绑定枚举的写法
原文:整理:WPF中Xaml中绑定枚举的写法 目的:在Combobox.ListBox中直接绑定枚举对象的方式,比如:直接绑定字体类型.所有颜色等枚举类型非常方便 一.首先用ObjectDataPro ...
- c# 字符串连接使用“+”和string.format格式化两种方式
参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...
- String.Format 格式化货币的小问题
今天在开发过程中,遇到一件让我觉得比较纳闷的事情:用String.Format 格式化充值金额的时候,我这样处理: String.Format("{0:C2}", dr[" ...
- 使用printf和String.format格式化输出
格式化输出 在哪些情况下使用格式化输出: 异常打印到日志中使用格式化输出有利于排查错误原因: printf格式化 示例: public class PrintfTest { public static ...
随机推荐
- hdu 六度分离
http://acm.hdu.edu.cn/showproblem.php?pid=1869 #include <cstdio> #include <cstring> #inc ...
- Chrome小技巧:如何下载离线版安装文件
每当chrome有更新之后,都有不少用户想要下载离线版的安装文件,但苦于找不到下载地址而发愁,其实这个问题很简单,下面我来分享一下方法(仅针对Windows操作系统): 对于稳定版(正式版)Chrom ...
- 【转】java中byte, int的转换, byte String转换
原文网址:http://freewind886.blog.163.com/blog/static/661924642011810236100/ 最近在做些与编解码相关的事情,又遇到了byte和int的 ...
- php5.3 appache phpstudy win7win8win10下 运行速度慢
php5.3 appache phpstudy win7win8win10下 运行速度慢 最近在部署服务器以及本地测试的时候发现了一个奇怪的现象,运行PHP程序的时候非常慢,起先以为是网速的原因,后经 ...
- IOS 用drawRect 画表格
自定义一个View DrawLine DrawLine.h #import <UIKit/UIKit.h> @protocol gridTouchDelete <NSObject&g ...
- [置顶] 创建GitHub技术博客全攻略
[置顶] 创建GitHub技术博客全攻略 分类: GitHub2014-07-12 13:10 19710人阅读 评论(21) 收藏 举报 githubio技术博客网站生成 说明: 首先,你需要注册一 ...
- Vue2.0环境搭建和测试demo
Vue2.0 推荐开发环境 Homebrew 1.0.6(Mac).Node.js 6.7.0.npm 3.10.3.webpack 1.13.2.vue-cli 2.4.0.Atom 1.10.2 ...
- vs2013 创建网站
从文件菜单中选择新建网站,版本选择4,如果选择更高级的版本在发布的时候老是会报错,暂时找不到解决的方法,所以就选择4这个版本了.选择asp的空网站,在下面选择文件系统. 项目建好后如下,然后添加一个w ...
- react-native使用react-art制作SVG动画
想要使用SVG做一个动画,郁闷了一上午终于有了一点思路.. 其实我是看了一篇国外的文章.网址:http://browniefed.com/blog/2015/05/03/getting-react-a ...
- JS 根据Url参数名称来获取对应的值 方法封装
function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...