我已經搜索計算器的解決方案,並發現這一點:日期格式
Need to format dates in dynamically built WPF DataGrid
我的問題是,我裝載一些數據我的SQL-Server的數據庫,並希望向他們展示在我的WPF應用程序中的DataGrid中。這工作得很好。 我想改變的唯一事情是日期列格式爲「DD/MM/YYYY HH:MM:SS」,我想要「DD.MM.YYYY」。 好了,然後我看了看下面的鏈接,並試圖在此我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時可以實現這種解決方案嗎? 如果不是,我該如何處理呢? 如果是,上面的代碼有什麼問題?
編輯: 我的問題解決了isn't因爲我決定不再重建我的應用程序,isn't那裏的AutoGenerateColumns =真正的解決方案?
好了,向你表示感謝! 如果沒有我的項目中的屬性,是否可以將列綁定到數據庫外的字段? – Harald
@Harald,不,你不能直接綁定到數據庫字段,首先你必須製作或生成一些對象(例如,使用[Entity Framework](http://msdn.microsoft.com/zh-cn/library/bb386876)的.aspx))。如果您已經擁有這些對象的集合,那麼您可以將它綁定到DataGrid.ItemsSource屬性,就像您在代碼中一樣。 – icebat
它幫助了我。謝謝 –