在 ViewSource 分组描述中使用部分日期 WPF C#
Using part of the Date in a ViewSource Grouping Description WPF C#
我有一个基于一组对象的可观察集合的 ViewSource,该集合基于一个名为 "Ticket" 的 c# class,用于 C# .net 4 中 WPF 项目的 DataGrid。该项目是对于一个简单的帮助台应用程序。
ViewSource 在 属性 调用 TktDate 时分组,当天输入的所有工单显然都在我的 DataGrid 中分组
不过,我最近更新了代码,因此 TktDate
现在不仅存储日期元素,还存储时间元素,所以很明显,当我只是想按日期分组时,我没有这样做,因为时间元素(我说的对吗?)..所以如果不清楚这里是屏幕截图
有没有办法对日期部分 TktDate 进行分组并忽略我的 ViewSource 的时间元素,或者我必须向我的 class 添加一个新的 属性 以仅存储日期部分并分组在新 属性 上?
查看下面class的属性
public class Ticket : INotifyPropertyChanged
{
public int userid { get; set; }
public int deptid { get; set; }
public int topicid { get; set; }
public int staffid { get; set; }
public int priorityid { get; set; }
public string poster { get; set; }
public DateTime TktDate { get; set; }
public string title { get; set; }
public string bodyopen { get; set; }
public string bodyclose { get; set; }
public string timespent { get; set; }
public string dayoffset { get; set; }
public string sysdt { get; set; }
public string Netdt { get; set; }
public string Teldt { get; set; }
public string Clidt { get; set; }
public string status { get; set; }
private string ticket;
public string Tket
在 TktDate
上的 ViewSource I 组中,它记录了工单创建的日期。分组代码如下,效果很好
CollectionViewSource ticketViewSource = ((CollectionViewSource)(this.FindResource("ticketViewSource")));
ticketViewSource.Source = TicketCol;
ticketDataGrid.DataContext = ticketViewSource;
//add grouping
if (ticketViewSource != null)
{
ticketViewSource.GroupDescriptions.Clear();
ticketViewSource.GroupDescriptions.Add(new PropertyGroupDescription("TktDate"));
ticketViewSource.SortDescriptions.Clear();
ticketViewSource.SortDescriptions.Add(new SortDescription("TktDate", ListSortDirection.Ascending));
}
Is there a way to Group on the date part TktDate
and ignore the time element for my ViewSource or must I add a new property to my class to store the date part only and group on the new property?
您可以尝试按嵌套 属性:
ticketViewSource.GroupDescriptions.Add(new PropertyGroupDescription("TktDate.Date"));
如果这不起作用,您应该添加一个新的 DateTime
只读 属性 到 Ticket
class 那 returns TktDate.Date
并按此分组。
我有一个基于一组对象的可观察集合的 ViewSource,该集合基于一个名为 "Ticket" 的 c# class,用于 C# .net 4 中 WPF 项目的 DataGrid。该项目是对于一个简单的帮助台应用程序。
ViewSource 在 属性 调用 TktDate 时分组,当天输入的所有工单显然都在我的 DataGrid 中分组
不过,我最近更新了代码,因此 TktDate
现在不仅存储日期元素,还存储时间元素,所以很明显,当我只是想按日期分组时,我没有这样做,因为时间元素(我说的对吗?)..所以如果不清楚这里是屏幕截图
有没有办法对日期部分 TktDate 进行分组并忽略我的 ViewSource 的时间元素,或者我必须向我的 class 添加一个新的 属性 以仅存储日期部分并分组在新 属性 上?
查看下面class的属性
public class Ticket : INotifyPropertyChanged
{
public int userid { get; set; }
public int deptid { get; set; }
public int topicid { get; set; }
public int staffid { get; set; }
public int priorityid { get; set; }
public string poster { get; set; }
public DateTime TktDate { get; set; }
public string title { get; set; }
public string bodyopen { get; set; }
public string bodyclose { get; set; }
public string timespent { get; set; }
public string dayoffset { get; set; }
public string sysdt { get; set; }
public string Netdt { get; set; }
public string Teldt { get; set; }
public string Clidt { get; set; }
public string status { get; set; }
private string ticket;
public string Tket
在 TktDate
上的 ViewSource I 组中,它记录了工单创建的日期。分组代码如下,效果很好
CollectionViewSource ticketViewSource = ((CollectionViewSource)(this.FindResource("ticketViewSource")));
ticketViewSource.Source = TicketCol;
ticketDataGrid.DataContext = ticketViewSource;
//add grouping
if (ticketViewSource != null)
{
ticketViewSource.GroupDescriptions.Clear();
ticketViewSource.GroupDescriptions.Add(new PropertyGroupDescription("TktDate"));
ticketViewSource.SortDescriptions.Clear();
ticketViewSource.SortDescriptions.Add(new SortDescription("TktDate", ListSortDirection.Ascending));
}
Is there a way to Group on the date part
TktDate
and ignore the time element for my ViewSource or must I add a new property to my class to store the date part only and group on the new property?
您可以尝试按嵌套 属性:
ticketViewSource.GroupDescriptions.Add(new PropertyGroupDescription("TktDate.Date"));
如果这不起作用,您应该添加一个新的 DateTime
只读 属性 到 Ticket
class 那 returns TktDate.Date
并按此分组。