https://github.com/syncfusionexamples/xamarin-forms-listview-custom-sorting
This example shows how to perform sorting using custom comparer in XForms ListView control.
https://github.com/syncfusionexamples/xamarin-forms-listview-custom-sorting
custom-sorting sorting xamarin xamarin-listview
Last synced: 3 months ago
JSON representation
This example shows how to perform sorting using custom comparer in XForms ListView control.
- Host: GitHub
- URL: https://github.com/syncfusionexamples/xamarin-forms-listview-custom-sorting
- Owner: SyncfusionExamples
- Created: 2019-07-31T07:20:45.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-09-24T10:55:11.000Z (9 months ago)
- Last Synced: 2025-10-09T06:05:54.184Z (8 months ago)
- Topics: custom-sorting, sorting, xamarin, xamarin-listview
- Language: C#
- Homepage:
- Size: 1.63 MB
- Stars: 0
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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;
}
}
```