【发布时间】:2010-01-02 22:10:57
【问题描述】:
在 WPF 应用程序中,我有一个 ListView:
<ListView Height="100" Width="434" Margin="0,2,0,0" x:Name="lvItems" ItemsSource="{Binding ElementName=MainWindow, Path=ShowQuCollection}" >
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="100" DisplayMemberBinding="{Binding Date}"/>
<GridViewColumn Header="Time" Width="100" DisplayMemberBinding="{Binding Time}"/>
<GridViewColumn Header="Description" Width="200" DisplayMemberBinding="{Binding Description}"/>
</GridView>
</ListView.View>
</ListView>
通过数据绑定与 ObservableCollection 连接。 ObservableCollection 是使用 LINQ to SQL 从 SQLServer db 表填充的。
ObservableCollection<ShowsQu> _ShowQuCollection =
new ObservableCollection<ShowsQu>();
public ObservableCollection<ShowsQu> ShowQuCollection
{ get { return _ShowQuCollection; } }
public class ShowsQu
{
public string ShowCode { get; set; }
public DateTime Date { get; set; }
public TimeSpan Time { get; set; }
public string Description { get; set; }
}
private void VisualizeAllShows()
{
MyfirstdbDataContext context = new MyfirstdbDataContext();
_ShowQuCollection.Clear();
var sh = from p in context.Shows select p;
foreach (var p in sh)
_ShowCollection.Add(new ShowsQu
{
Date = p.Date,
Time = p.Time,
Description = p.Description
});
}
问题在于 ListView 按原样显示 SQLServer 数据库表中的日期字段 - 没有应用特定于区域的格式(我猜它应该默认应用)。
我应该在哪里以及如何将其格式化为 PC 区域设置的格式?
【问题讨论】:
标签: c# wpf linq-to-sql data-binding listview