|
<syncfusion:SfListView x:Name="ToDoListView"
ItemSize="60"
IsStickyHeader="True"
ItemsSource="{Binding ToDoList}"
DragStartMode="OnHold,OnDragIndicator"
SelectionMode="None">
<syncfusion:SfListView.DragDropController>
<syncfusion:DragDropController UpdateSource="True"/>
</syncfusion:SfListView.DragDropController>
...
<syncfusion:SfListView.ItemTemplate>
<DataTemplate>
<Grid>
...
<Label Text="{Binding ., Converter={StaticResource indexConverter}, ConverterParameter={x:Reference ToDoListView}}" Grid.Column="1" Margin="5,3,0,0" VerticalOptions="Center" HorizontalOptions="Start" />
...
</Grid>
</DataTemplate>
</syncfusion:SfListView.ItemTemplate>
</syncfusion:SfListView> |
|
public class IndexConverter : IValueConverter
{
SfListView ListView;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return 0;
var item = value as ToDoItem;
ListView = parameter as SfListView;
var groupresult = GetGroup(item);
var dropGroupList = groupresult.GetType().GetRuntimeProperties().FirstOrDefault(method => method.Name == "ItemList").GetValue(groupresult) as List<object>;
return groupresult.Key.ToString() + " " + dropGroupList.IndexOf(item);
}
private GroupResult GetGroup(object itemData)
{
GroupResult itemGroup = null;
foreach (var item in this.ListView.DataSource.DisplayItems)
{
if (item == itemData)
break;
if (item is GroupResult)
itemGroup = item as GroupResult;
}
return itemGroup;
}
} |
|
public class Behavior : Behavior<ContentPage>
{
SfListView ListView;
protected override void OnAttachedTo(ContentPage bindable)
{
ListView = bindable.FindByName<SfListView>("ToDoListView");
ListView.ItemDragging += ListView_ItemDragging;
base.OnAttachedTo(bindable);
}
private void ListView_ItemDragging(object sender, ItemDraggingEventArgs e)
{
if (e.Action == DragAction.Drop)
{
Device.BeginInvokeOnMainThread(() => ListView.RefreshListViewItem(-1, -1, true));
}
}
} |