diff --git a/README.md b/README.md index 6474b70..2aa250f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,61 @@ # show-reordered-index-listview-xamarin How to show the reordered sorted index in Xamarin.Forms ListView (SfListView) + +## Sample + +```xaml + + + + + + + + + + + + + + + + . . . + . . . + + + + + +C#: +ListView.ItemDragging += ListView_ItemDragging; + +private void ListView_ItemDragging(object sender, ItemDraggingEventArgs e) +{ + if (e.Action == DragAction.Drop) + { + if (e.NewIndex < e.OldIndex) + { + Device.BeginInvokeOnMainThread(() => ListView.RefreshListViewItem(-1, -1, true)); + }; + } +} + +Converter: +public class IndexConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) return 0; + + var item = value as ToDoItem; + var listView = parameter as SfListView; + return listView.DataSource.DisplayItems.IndexOf(item); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} +```