Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,61 @@
# show-reordered-index-listview-xamarin
How to show the reordered sorted index in Xamarin.Forms ListView (SfListView)

## Sample

```xaml
<ContentPage.Resources>
<ResourceDictionary>
<local:IndexConverter x:Key="indexConverter"/>
</ResourceDictionary>
</ContentPage.Resources>

<syncfusion:SfListView x:Name="ToDoListView" ItemSize="60" IsStickyHeader="True" IsScrollBarVisible="False"
ItemsSource="{Binding ToDoList}" DragStartMode="OnHold,OnDragIndicator" SelectionMode="None">

<syncfusion:SfListView.DragDropController>
<syncfusion:DragDropController UpdateSource="True"/>
</syncfusion:SfListView.DragDropController>

<syncfusion:SfListView.ItemTemplate>
<DataTemplate>
<code>
. . .
. . .
<code>
</DataTemplate>
</syncfusion:SfListView.ItemTemplate>
</syncfusion:SfListView>

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();
}
}
```