需要在动态构建的WPF DataGrid格式化日期 [英] Need to format dates in dynamically built WPF DataGrid

查看:358
本文介绍了需要在动态构建的WPF DataGrid格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行时我们将一个未知的结果集绑定到WPF DataGrid。我们的一些列将包含DateTime值,我们需要正确格式化这些日期时间字段。不知道在设计时哪些列将是DateTime字段,我们如何能够在运行时格式化列?

We are binding an unknown result set to a WPF DataGrid at run time. Some of our columns are going to contain DateTime values and we need to properly format these date time fields. Without knowing which columns are going to be DateTime fields at design time, how are we able to format the columns at runtime?

我们正在使用DataTable的DefaultView绑定到WPF DataGrid。

We are using a DataTable's DefaultView to bind to the WPF DataGrid.

推荐答案

<wpfToolkit:DataGridTextColumn Header="Fecha Entrada" Width="110"  
                                   Binding="{Binding EnterDate,StringFormat={}\{0:dd/MM/yyyy hh:mm\}}" IsReadOnly="True" />

我认为比编写更大的代码要好

I think it's better than writing bigger pieces of code

这篇关于需要在动态构建的WPF DataGrid格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆