日期格式在WPF数据网格 [英] Date formatting in WPF datagrid

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

问题描述

我已经搜查计算器的解决方案,并发现这一点:

I already searched stackoverflow for a solution and found this:

需要格式化的动态构建WPF的DataGrid

我的问题是,我加载一些数据我的SQL-Server的数据库,并希望向他们展示在一个DataGrid我的WPF应用程序。这工作得很好。
我想改变的唯一的事情是,日期列的格式为DD / MM / YYYY HH:MM:SS,我想有DD.MM.YYYY。
好吧,那么我看着下面的链接,在我PROGRAMM尝试这样的:

My problem is, that I load some data out of my SQL-Server-Database and want to show them in my WPF-application in a DataGrid. This works very well. The only thing I want to change is that the date column is in the format "DD/MM/YYYY HH:MM:SS" and I want to have "DD.MM.YYYY". Ok, then I looked at the link below and tried this in my programm:

<Grid Width="648" Height="263">

  <Grid.ColumnDefinitions>
       <ColumnDefinition Width="172*" />
       <ColumnDefinition Width="90*" />
       <ColumnDefinition Width="386*" />
  </Grid.ColumnDefinitions>

  <DataGrid Name="dgBuchung" Height="213" HorizontalAlignment="Left" Margin="30,16,0,0"     VerticalAlignment="Top" Width="595" AutoGenerateColumns="True" ItemsSource="{Binding}" Grid.ColumnSpan="3" Foreground="Black" BorderBrush="#FF688CAF" Opacity="1" Background="White" BorderThickness="1" >
 <!-- <ab:DataGridTextColumn Header="Fecha Entrada" Width="110"  
       Binding="{Binding date, StringFormat={}{0:dd/MM/yyyy}}" IsReadOnly="True" />
                        -->
</DataGrid>

</Grid>

的评论出来的部分是我的解决方式,但它抛出一个XMLParseException。
首先,是解决这一可能的方式,而使用的AutoGenerateColumns?
。如果没有,怎么回事我可以尝试来处理呢?
。如果是,什么是与上面的代码中的问题。

The out commented part is my way of solution but it throws a XMLParseException. First of all, is this way of solution possible while using AutoGenerateColumns? If no, how else can I try to handle this? If yes, what is the problem with the code above?

编辑:
我的问题解决了isn't因为我决定不再重建我的应用程序,isn't那里的AutoGenerateColumns =真?

My question isn´t solved because I decided not to rebuild my application, isn´t there a solution with AutoGenerateColumns=true?

推荐答案

解决方案唐`忘了使用DataGrid.Columns,所有列必须是集合中。
在我的项目我日期格式有点不同:

Don`t forget to use DataGrid.Columns, all columns must be inside that collection. In my project I format date a little bit differently:

<tk:DataGrid>
    <tk:DataGrid.Columns>
        <tk:DataGridTextColumn Binding="{Binding StartDate, StringFormat=\{0:dd.MM.yy HH:mm:ss\}}" />
    </tk:DataGrid.Columns>
</tk:DataGrid>

使用的AutoGenerateColumns您那倒能控逆变格式化为DataGird将增加其自身的列。

With AutoGenerateColumns you won`t be able to contol formatting as DataGird will add its own columns.

这篇关于日期格式在WPF数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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