WPF中StringFormat 格式化 的用法
网格用法
<my:DataGridTextColumn x:Name="PerformedDate" Header="执行时间" Binding="{Binding PerformedDate,StringFormat='yyyy年MM月dd日'}" Width="100" />
<my:DataGridTextColumn x:Name="LubricatingOilActualUsage" Header="润滑油用量" Binding="{Binding LubricatingOilActualUsage,StringFormat=' {0}升'}" Width="100" />
1、
C#中用法:
格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元)示例:
string.Format("{0:C}",0.2) 结果为:¥0.10 (英文操作系统结果:$0.10)
默认格式化小数点后面保留两位小数,如果需要保留一位或者更多,可以指定位数
string.Format("{0:C1}",10.05) 结果为:¥10.1 (截取会自动四舍五入)
格式化多个Object实例 string.Format("会员价:{0:C},优惠价{1:C}",99.15,109.25)
WPF中用法:
格式化货币示例:
<TextBox Name="txtPrice" HorizontalAlignment="Left" Width="170" Height="24" VerticalAlignment="Top" Background="White">
<TextBox.Text>
<Binding Path="Price" StringFormat="{}{0:C}"/>
</TextBox.Text>
</TextBox>
2、
C#中用法:
格式化十进制的数字(格式化成固定的位数,位数不能少于未格式化前,只支持整形)示例:
string.Format("{0:D3}",99) 结果为:099
string.Format("{0:D2}",1234) 结果为:1234,(精度说明符指示结果字符串中所需的最少数字个数。)
WPF中用法:
格式化十进制的数字示例:
<TextBox Name="txtRoomCount" HorizontalAlignment="Left" Width="170" Height="24" VerticalAlignment="Top" Background="White">
<TextBox.Text>
<Binding Path="RoomCount" StringFormat="{}{0:D2}"/>
</TextBox.Text>
</TextBox>
3、
C#中用法:
用分号隔开的数字,并指定小数点后的位数示例:
string.Format("{0:N}", 12300) 结果为:12,300.00 (默认为小数点后面两位)
string.Format("{0:N3}", 12300.1234) 结果为:12,300.123(自动四舍五入)
WPF中用法:
同格式化十进制的数字示例
4、
C#中用法:
格式化百分比示例:
string.Format("{0:P}", 0.12341) 结果为:12.34% (默认保留百分的两位小数)
string.Format("{0:P1}", 0.1256) 结果为:12.6% (自动四舍五入)
WPF中用法:
同格式化十进制的数字示例
5、
C#中用法:
零占位符和数字占位符示例:
string.Format("{0:0000.00}", 12345.015) 结果为:12345.02
string.Format("{0:0000.00}", 123.015) 结果为:0123.02
string.Format("{0:###.##}", 12345.015) 结果为:12345.02
string.Format("{0:####.#}", 123.015) 结果为:123194
WPF中用法:
同格式化十进制的数字示例
6、
C#中用法:
日期格式化示例:
string.Format("{0:d}",System.DateTime.Now) 结果为:2010-6-19 (月份位置不是06)
string.Format("{0:D}",System.DateTime.Now) 结果为:2010年6月19日
string.Format("{0:f}",System.DateTime.Now) 结果为:2010年6月19日 20:30
string.Format("{0:F}",System.DateTime.Now) 结果为:2010年6月19日 20:30:10
string.Format("{0:g}",System.DateTime.Now) 结果为:2010-6-19 20:30
string.Format("{0:G}",System.DateTime.Now) 结果为:2010-6-19 20:30:10
string.Format("{0:m}",System.DateTime.Now) 结果为:6月19日
string.Format("{0:t}",System.DateTime.Now) 结果为:20:30
string.Format("{0:T}",System.DateTime.Now) 结果为:20:30:10
string.Format("{0:yyyy-MM-dd HH:mm}",System.DateTime.Now) 结果为:2010-6-19 20:30
string.Format("{0:yyyy-MM-dd }",System.DateTime.Now) 结果为:2010-6-19
WPF中用法:
日期格式化示例:
<TextBox Name="txtCreateTime" HorizontalAlignment="Left" Width="170" Height="24" VerticalAlignment="Top" Background="White">
<TextBox.Text>
<Binding Path="CreateTime" StringFormat="{}{0:yyyy-MM-dd HH:mm}"/>
</TextBox.Text>
</TextBox>
WPF中StringFormat 格式化 的用法的更多相关文章
- WPF中StringFormat的用法
原文:WPF中StringFormat的用法 WPF中StringFormat的用法可以参照C#中string.Format的用法 1. C#中用法: 格式化货币(跟系统的环境有关,中文系统默认格式化 ...
- WPF中StringFormat的用法--显示特定位数的数字
原文:WPF中StringFormat的用法--显示特定位数的数字 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/art ...
- WPF中InkCanvas(墨水面板)用法
原文:WPF中InkCanvas(墨水面板)用法 WPF中InkCanvas(墨水面板)用法 ...
- python中实现格式化输出 %用法
当我们在python中需要打印出特定格式的内容时可以用到这个方法,方法介绍如下: 例如我们现在要收集用户的一些个人信息,这时候我们的代码如下: name=input("name: " ...
- WPF 中RichTextBox控件用法细讲
1. 取得已被选中的内容:(1)使用RichTextBox.Document.Selection属性(2)访问RichTextBox.Document.Blocks属性的“blocks”中的Text ...
- smarty 中时间格式化的用法
大家都知道PHP中输出时间和日期可以用 date("Y-m-d H:i:s",时间戳) , 但是在smarty模板中,$time|date_format:'%Y-%m-%d %H ...
- WPF StringFormat 格式化文本
StringFormat对特定数据格式的转换 WPF中,对数字/日期等的格式化,可参考此篇博客:https://www.cnblogs.com/zhengwen/archive/2010/06/19/ ...
- WPF中Binding使用StringFormat格式化字符串方法
原文:WPF中Binding使用StringFormat格式化字符串方法 货币格式 <TextBlock Text="{Binding Price, StringFormat={}{0 ...
- WPF中log4net的用法
WPF中如何使用log4nethttp://www.cnblogs.com/C-Sharp2/archive/2013/04/12/WPF-LOG4NET.html Apache log4net Ma ...
随机推荐
- mapper分页排序指定字段查询模板
StudentQuery: package Student; import java.util.ArrayList; import java.util.List; public class Stude ...
- AngularJS Factory Service Provider
先看看http://www.cnblogs.com/mbydzyr/p/3460501.html http://www.oschina.net/translate/angularjs-factory- ...
- Qt的“undefined reference to `vtable for”错误解决(手动解决,加深理解)
使用QT编程时,当用户自定义了一个类,只要类中使用了信号或槽. Code::Blocks编译就会报错(undefined reference to `vtable for). Google上有很多这个 ...
- shouldOverrideUrlLoading相关说明
给WebView加一个事件监听对象(WebViewClient)并重写其中的一些方法:shouldOverrideUrlLoading:对网页中超链接按钮的响应.当按下某个连接时WebViewClie ...
- HDU 2501 Tiling_easy version
递推式:f[n]=2*f[n-2]+f[n-1] #include <cstdio> #include <iostream> using namespace std; ]; i ...
- Java_java多线程下载-断点下载-超详细
基本原理:利用URLConnection获取要下载文件的长度.头部等相关信息,并设置响应的头部信息.并且通过URLConnection获取输入流,将文件分成指定的块,每一块单独开辟一个线程完成数据的读 ...
- centos 安装 erlang
1.首先下载erlang 安装源文件 可以在官网上下载 : http://www.erlang.org/ 官网上提供多个版本: 2.下载完成后将R16B01 Source File对应的 ot ...
- 实现AJAX局部刷新以及PageMethod方法的使用
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...
- HDU 4548(美素数)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 小明对数的 ...
- django 基础入门(二)
一.关于数据库 1.首先django 1.9以上等版本不支持pymysql,因此需要做一些调整. 比如在settings.py 加入一段代码: import pymysql pymysql.insta ...