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

查看:38
本文介绍了需要在动态构建的 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.

推荐答案

通过 StringFormat 格式化绑定:

<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 code behind pieces of code

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

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