我有一盏银光灯 DataGrid 每个列都填充了不同类型的数据。我想知道如何格式化 数据网格 的单元格,特别是日期和格式。
DataGrid
数据网格
我有一个日期栏,当前显示如下: 2010年11月3日上午12:00:00 . 我宁愿它像 3/14/2010 .
我有一个数字列,当前显示如下: 五十一点三二 . 我宁愿它显示为货币 51.32美元 .
我不知道该怎么做。我宁愿用xaml而不是c,但这两种解决方案都很好。
作为参考,这是我到目前为止的xaml:
</data:DataGridTextColumn> <data:DataGridTextColumn Header="Payee" Binding="{Binding Payee}"/> <data:DataGridTextColumn Header="Category" Binding="{Binding Category}"/> <data:DataGridTextColumn Header="Memo" Binding="{Binding Memo}"/> <data:DataGridTextColumn Header="Inflow" Binding="{Binding Inflow}"/> <data:DataGridTextColumn Header="Outflow" Binding="{Binding Outflow}"/> </data:DataGrid.Columns>
您可以使用基于string.format的ivalueconverter并将其绑定到xaml中。
Check out how to do it here
Yet another article to address the same
如果你有可能等待silverlight 4的发布,可能在下周的mix10。它在绑定中有一些新特性,比如格式化。使用Silverlight 4,您可以执行以下操作:
<TextBox Text="{Binding ReleaseDate, StringFormat='MMM dd, yyyy', Mode=TwoWay}" />
Shawn Wildermuth对 his blog .