在WPF datadrid中格式化单元格值 [英] Format cell values in WPF datadrid
问题描述
我在WPF数据网格中有一个列,它通过ItemSource绑定到XML文件。
我想格式化该数据网格中的一列,为每个第六个字符添加一个逗号。
因此,如果该值 001453004309004317004465028142322000349829500183977995996660X01941
,它将执行以下操作;
001453,004309,004317 ,004465,028142,322000,349829,500183,977995,996660,X01941
谢谢
从这里开始: DataGrid类 [ ^ ]
在相关网站的底部,您将找到格式化电子邮件地址的方法。你必须在同一件事上做到这一点。
你将用来将字符串转换为逗号分隔字符串的类可以使用如下方法:
public string CommaAt6thChar( string customString)
{
return customString.Aggregate( ,(结果,c)= > 结果+ =((!string。 IsNullOrEmpty(结果)&&(result.Length + 1 )% 7 == 0 )? ,: )+ c.ToString());
}
如需了解更多信息,请参阅:
使用绑定的WPF DataGrid格式指南 [ ^ ] br />
Enumerable.Aggregate< TSource>方法 [ ^ ]
I have a column in a WPF datagrid that is bound to an XML file via ItemSource.
I want to format one column in that datagrid to add a comma to every sixth char.
So if the value was 001453004309004317004465028142322000349829500183977995996660X01941
, it would do the following;
001453,004309,004317,004465,028142,322000,349829,500183,977995,996660,X01941
Thank You
Start here: DataGrid Class[^]
At the bottom of related site, you'll find a method to format email address. You have to do that in the same matter.
A class which you'll use to convert string into comma separated string can use method as follow:
public string CommaAt6thChar(string customString) { return customString.Aggregate("", (result, c) => result += ((!string.IsNullOrEmpty(result) && (result.Length + 1) % 7 == 0) ? "," : "") + c.ToString()); }
For further information, please see:
Guide to WPF DataGrid formatting using bindings[^]
Enumerable.Aggregate<TSource> Method [^]
这篇关于在WPF datadrid中格式化单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!