namespace TabView
{
public class Behavior :Behavior<SfListView>
{
SfListView ListView;
ViewModel ViewModel;
protected override void OnAttachedTo(SfListView listView)
{
ListView = listView;
ViewModel = new ViewModel();
ViewModel = listView.BindingContext as ViewModel;
ListView.ItemDragging += ListView_ItemDragging;
ListView.DataSource.LiveDataUpdateMode = Syncfusion.DataSource.LiveDataUpdateMode.AllowDataShaping;
base.OnAttachedTo(listView);
}
private async void ListView_ItemDragging(object sender, ItemDraggingEventArgs e)
{
if (e.Action == DragAction.Drop)
{
if (e.OldIndex < e.NewIndex)
{
await Task.Delay(100);
ChangeData(e);
}
}
}
private void ChangeData(ItemDraggingEventArgs e)
{
ViewModel.ToDoList.MoveTo(e.OldIndex, e.NewIndex);
var position = e.Position.Y;
var itemSize = 0;
for (int i = 0; i < ViewModel.ToDoList.Count; i++)
{
(ViewModel.ToDoList[i] as ToDoItem).OrderPosition = position + itemSize;
itemSize += 60;
}
}
}
} |