【发布时间】:2011-08-08 15:59:33
【问题描述】:
我有一个绑定到对象集合的列表视图。其中一个属性是名为 startDate 的 DateTime 对象。它以标准的 1/1/2001 1:00:00 PM 格式显示
我想以 yyyy-MM-dd HH:mm:ss.fff 格式输入日期,仅用于显示目的。有没有办法在以上面所需的格式显示底层 DateTime 对象时保持其完整?我更喜欢在 XAML 中执行此操作,而不是向对象添加显示属性或类似的东西。
对象实现 INotifyPropertyChanged 接口,如果这很重要的话。
<ListView x:Name="lvBatches"
SelectionMode="Single"
Margin="12,73,349,61"
Background="WhiteSmoke"
SelectionChanged="lvBatches_SelectionChanged"
ToolTip="Click on the column headers to sort by that column"
FontSize="10pt"
ItemContainerStyle="{StaticResource itemStyle}"
ItemsSource="{Binding batchCollection}">
<!-- ... -->
<GridViewColumn x:Name="colStart"
Width="200"
DisplayMemberBinding="{Binding startDate}">
<GridViewColumnHeader Content="Start Date"
Click="GridViewColumnHeader_Click"/>
</GridViewColumn>
提前谢谢大家。
【问题讨论】:
标签: c# wpf data-binding listview date-format