Articles in this section
Category / Section

How to show or hide the drag indicator like iOS in Xamarin ListView?

1 min read

Xamarin ListView allows you show or hide the drag indicator like native iOS applications using the visibility property in the ItemDragging event. The following code sample demonstrates how to show or hide the drag indicator.

Xaml

<ContentPage xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms">
    <ContentPage.Behaviors>
        <local:Behavior/>
    </ContentPage.Behaviors>
    <Grid>
        <Button x:Name="editButton" Text="Click to show drag indicator" Command="{Binding TapCommand}"/>
        <syncfusion:SfListView x:Name="listView" 
                           ItemsSource="{Binding ContactsInfo}"
                           ItemSize="70"
                           DragStartMode="OnHold,OnDragIndicator"
                           SelectionMode="None">
            <syncfusion:SfListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <syncfusion:DragIndicatorView IsVisible="{Binding IndicatorVisible}" ListView="{x:Reference listView}">
                            <Grid>
                                <Image Source="DragIndicator.png"/>
                            </Grid>
                        </syncfusion:DragIndicatorView>
                        <Label LineBreakMode="NoWrap"
                           Text="{Binding ContactName}"/>
                        <Label LineBreakMode="NoWrap"
                           Text="{Binding ContactNumber}"/>
                        <Label LineBreakMode="NoWrap"
                           Text="{Binding ContactType}"/>
                    </Grid>
                </DataTemplate>
            </syncfusion:SfListView.ItemTemplate>
        </syncfusion:SfListView>
    </Grid>
</ContentPage>
 

 

C#

public class ListViewGroupingViewModel
{
    #region Constructor
 
    public ListViewGroupingViewModel()
    {
        GenerateSource();
        TapCommand = new Command<object>(OnTapped);
    }
 
    #endregion
    private void OnTapped(object obj)
    {
        for (int i = 0; i < ContactsInfo.Count; i++)
        {
            ContactsInfo[i].IndicatorVisible = true;
        }
    }
}

 

class Behavior : Behavior<ContentPage>
{
    ListViewGroupingViewModel viewModel;
    Button button;
    public SfListView listview { get; private set; }
    protected override void OnAttachedTo(ContentPage bindable)
    {
        base.OnAttachedTo(bindable);
        listview = (bindable as ContentPage).FindByName<SfListView>("listView");
        button = (bindable as ContentPage).FindByName<Button>("editButton");
        viewModel = new ListViewGroupingViewModel();
        listview.BindingContext = viewModel;
        button.BindingContext = viewModel;
        listview.ItemDragging += Listview_ItemDragging;
    }
 
    private void Listview_ItemDragging(object sender, ItemDraggingEventArgs e)
    {
        if (e.Action == Syncfusion.ListView.XForms.DragAction.Drop)
        {
            for (int i = 0; i < viewModel.ContactsInfo.Count; i++)
            {
                viewModel.ContactsInfo[i].IndicatorVisible = false;
            }
        }
    }
    protected override void OnDetachingFrom(ContentPage bindable)
    {
        base.OnDetachingFrom(bindable);
        listview.ItemDragging -= Listview_ItemDragging;
        listview = null;
        button = null;
    }
}

 

Sample: Show or hide indicator like native iOS application

Conclusion

I hope you enjoyed learning about how to show or hide the drag indicator like iOS in Xamarin ListView.

You can refer to our Xamarin.Forms ListView feature tour page to know about its other groundbreaking feature representations. You can also explore our Xamarin.Forms ListView documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied