diff --git a/README.md b/README.md index af63b7b..3509f74 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,69 @@ # xamarin-forms-listview-custom-sorting Xamarin Forms ListView provides support to custom sort the items using Comparer. + +## Sample + +```xaml + + + + + + + + + + + + + + + + + + + + . . . + . . . + + + + + + + +CustomSortComparer: +public class CustomSortComparer : IComparer +{ + public int Compare(object x, object y) + { + if (x.GetType() == typeof(ListViewContactsInfo)) + { + var xitem = (x as ListViewContactsInfo).ContactName; + var yitem = (y as ListViewContactsInfo).ContactName; + + if (xitem.Length > yitem.Length) + { + return 1; + } + else if (xitem.Length < yitem.Length) + { + return -1; + } + else + { + if (string.Compare(xitem, yitem) == -1) + return -1; + else if (string.Compare(xitem, yitem) == 1) + return 1; + } + } + + return 0; + } +} +```