diff --git a/README.md b/README.md index abed25e..1738827 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,77 @@ # how-to-sort-the-items-based-on-date-time-along-with-groups-in-.net-maui-listview + This example demonstrates how to sort the items based on date time along with the groups in .NET MAUI ListView + +## XAML + + + + + + + + + + + + + + + + + + + + + + + + + + +## C# + class CustomGroupComparer : IComparer, ISortDirection + { + public CustomGroupComparer() + { + this.SortDirection = ListSortDirection.Ascending; + } + + public ListSortDirection SortDirection + { + get; + set; + } + + public int Compare(GroupResult x, GroupResult y) + { + DateTime xvalue = Convert.ToDateTime(x.Key); + DateTime yvalue = Convert.ToDateTime(y.Key); + + // Group results are compared and return the SortDirection + if (xvalue.CompareTo(yvalue) > 0) + return SortDirection == ListSortDirection.Ascending ? 1 : -1; + else if (xvalue.CompareTo(yvalue) == -1) + return SortDirection == ListSortDirection.Ascending ? -1 : 1; + else + return 0; + } + } + +## Requirements to run the demo + +* [Visual Studio 2017](https://visualstudio.microsoft.com/downloads/) or [Visual Studio for Mac](https://visualstudio.microsoft.com/vs/mac/) +* Xamarin add-ons for Visual Studio (available via the Visual Studio installer). + +## Troubleshooting + +### Path too long exception + +If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project. \ No newline at end of file