New to Telerik UI for .NET MAUI? Start a free 30-day trial

Disabling Right or Left Swipe in CollectionView for .NET MAUI

Environment

Version Product Author
10.0.0 CollectionView for .NET MAUI Dobrinka Yordanova

Description

You're using the CollectionView in a .NET MAUI application and have enabled item swiping by setting IsItemSwipeEnabled to true. However, you want to disable either the left or right swipe action while keeping the order direction functional.

This knowledge base article also answers the following questions:

  • How to disable right swipe in CollectionView?
  • How to disable left swipe in CollectionView?
  • Can I enable only left swipe in CollectionView for .NET MAUI?
  • Can I enable only right swipe in CollectionView for .NET MAUI?
  • How to handle swipe actions differently in CollectionView?

Solution

To disable the right swipe (left-to-right swipe direction) in a RadCollectionView while allowing the left swipe (right-to-left direction), subscribe to the Swiping event. In the event handler, determine the swipe direction by examining the Offset property. If the Offset is less than 0, indicating a right-to-left swipe direction, then call the EndItemSwipe() method to cancel the swipe action.

If you want to disable the left swipe (right-to-left swipe direction) the Offset must be greater than 0.

1. Define the RadCollectionView in XAML:

<telerik:RadCollectionView x:Name="collectionView"
                           IsItemSwipeEnabled="True"
                           Swiping="collectionView_Swiping">

2. Implement the event handler in your code-behind to disable the right swipe:

private void collectionView_Swiping(object sender, Telerik.Maui.Controls.CollectionView.CollectionViewSwipingEventArgs e)
{
    // Disable right swipe (left-to-right direction)
    //if (e.Offset > 0)
    //{
    //  this.collectionView.EndItemSwipe(false);
    //}

    // Disable left swipe (right-to-left direction)
    if (e.Offset < 0)
    {
        this.collectionView.EndItemSwipe(false);
    }
}

By using this approach, the collection view will only respond to right swipes, effectively disabling the left swipe functionality.

See Also

In this article