public int Compare(object x, object y) { var castDateX = ObservableObject.GetPropValue(x, "Model.NgayLapDate").ToString(); var castDateY = ObservableObject.GetPropValue(y, "Model.NgayLapDate").ToString(); if (castDateX != null && castDateY != null) { try { var dateX = DateTime.ParseExact(castDateX, "dd/MM/yyyy", null); var dateY = DateTime.ParseExact(castDateY, "dd/MM/yyyy", null); if (SortDirection == ListSortDirection.Ascending) { return(dateX.CompareTo(dateY)); } else { return(dateX < dateY ? 1 : dateX == dateY ? 0 : -1); } } catch { throw new InvalidCastException($"Cannot cast from {typeof(string)} to {typeof(DateTime)}"); } } throw new ArgumentException($"Argument is not of type {typeof(ItemViewModel<PhieuBanModel>)}"); }
public static bool ConvertToTableRow(ObservableObject obj, string[] propertyNames, TableRow headerRow, out TableRow tableRow) { tableRow = new TableRow(); for (int i = 0; i < propertyNames.Length; i++) { try { object propValue = ObservableObject.GetPropValue(obj, propertyNames[i]); TableCell cell = new TableCell(); cell.Blocks.Add(new Paragraph(new Run(propValue.ToString()))); ApplyHeaderCellStyleToDataCell(cell, headerRow.Cells[i]); tableRow.Cells.Add(cell); } catch { tableRow = null; return(false); } } return(true); }