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} {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 -->
转载于:https://www.cnblogs.com/changbaishan/p/5365330.html
WPF中XAML中使用String.Format格式化字符串示例相关推荐
- java 补齐字符串_使用String.format()格式化字符串,java自动补全自增长字符串
JDK1.5中,String类新增了一个很有用的静态方法String.format(): format(Locale l, String format, Object... args) 使用指定的语言 ...
- string.Format 格式化字符串
http://www.cnblogs.com/linyechengwei/archive/2009/11/17/1604509.html 今天在做项目时,碰到一个很奇怪的问题,我使用string.Fo ...
- String.format() 格式化字符串
1.几种常见的转换符 转换符 说明 实例 %d 整数类型(十进制) 99 %f 浮点类型 99.99 %s 字符串类型 "mingrisoft" %c 字符类型 'm' %b 布尔 ...
- asp:HyperLink中 Eval要用string.Format绑定
asp:HyperLink中 Eval要用string.Format绑定 <asp:HyperLink ID="hlAlter" runat="server&quo ...
- C#字符串- string.Format格式化
转自:https://www.cnblogs.com/itjeff/p/5775665.html C# string.Format对字符串格式化 String.Format 方法的几种定义: Stri ...
- string.Format 格式化输出
string.Format 格式化输出 资料参考: http://msdn.microsoft.com/zh-cn/library/26etazsy(v=VS.80).aspx string.Form ...
- Python基础教程:format 格式化字符串用法
1.format 格式化字符串 (1) 顺序传参 (2) 索引传参 (3) 关键字传参 (4) 容器类型传参 {} 代表的是占位符 2.顺序传参 strvar = "{}向{}开了一枪&qu ...
- java字符串 大括号_string.format格式化字符串中转义大括号“{}”
今天,用Java读取配置文件占位符,使用String.Format(string format,object arg0)方法.以前只知"{0}"为索引占位符(即格式项),与参数列表 ...
- python 大括号转义_string.format格式化字符串中转义大括号“{}”
今天,用C#写程序操作Excel,读取单元格内容根据所需格式生成字符串,使用String.Format(string format,object arg0)方法.以前只知"{0}" ...
- 我的Android进阶之旅------Java字符串格式化方法String.format()格式化float型时小数点变成逗号问题...
今天接到一个波兰的客户说有个APP在英文状态下一切运行正常,但是当系统语言切换到波兰语言的时候,程序奔溃了.好吧,又是我来维护. 好吧,先把系统语言切换到波兰语,切换到波兰语的方法查看文章 我的And ...
最新文章
- 两个整数相加 相乘 有符号与无符号 溢出判断条件 移位与2的幂
- POJ 3009 Curling 2.0(简单DFS)
- 安卓文本编辑器php cpp,开源的Android富文本编辑器
- java数组按某个值排序_Js--使用sort根据数组中对象的某一个属性值进行排序
- Leetcode每日一题:54.spiral-matrix(螺旋矩阵)
- 网络流 poj 2195
- Linux下安装常用软件
- 想以游戏纸娃娃系统专利主张暴雪的暗黑3侵权? 先过暗黑2这关!
- IBM SPSS Modeler简单案例
- 弹性波波长计算公式_固体中的弹性波
- 2020最新抖音上热门技巧你知道了几个?
- 数组扁平化的方法汇总
- 推荐一些Windows系统中好用的免费(开源)/收费的终端管理工具(命令行工具)
- 朱啸虎是如何投到国内第一家 PLG 独角兽的 | 风云投资人
- qq空间把android改成iphone,装逼时代 教你如何修改QQ微信小尾巴为来自iphone6
- 很不错的免费电影网站中国影视库mdbchina.com
- 三-五功能/半亮/25%亮/全亮/爆闪/SOS_专用应急灯手电筒IC方案
- 【yoyo】移入切换
- bootstrap开源的后台管理系统模板
- php如何实现上一篇下一篇的功能
热门文章
- Akka Remote Actor_简单示例二
- Python中__init__和__del__方法介绍
- 写给初学asp.net的新人们 新手学习经验
- linux awk数组使用
- 突然想起今天的博客汇报没写
- 4.熟悉App Inventor 2编程界面
- JavaScript:学习笔记(7)——VAR、LET、CONST三种变量声明的区别
- Python_遍历时删除的处理说明
- MySQL入门第三天(下)——存储过程与存储引擎
- 1:A+B Problem