How do I avoid the Content covering revealed SwipeItems in CollectionView?

dg2k 1,416 Reputation points
2023-06-22T08:18:04.52+00:00

I am trying to implement SwipeView based UI (MAUI Android) for CollectionView list items Edit and Delete actions. The issue I am having is that when I swipe to reveal the UI for invoking actions through tap, the list item Content (in my case Text) is still covering part of a SwipeItem which is less than ideal.

I understand that I can push the Content away from the revealed SwipeItems by setting the Threshold property value, but again the problem is that the SwipeItems expand to fill in the available space which defeats the whole purpose of setting the Threshold. If SwipeItems do not expand with increased Threshold, then, everything would be perfect.

Not sure if this is a bug with CollectionView as I have had a reported issue with CollectionView under WinUI. The current issue is with Android platform. Any workaround to avoid the list item content covering SwipeItems is appreciated.

<CollectionView.ItemTemplate>
    <DataTemplate x:DataType="model:Reminder">
        <SwipeView
            Margin="0"
            Padding="0"
            Threshold="300">

            <SwipeView.LeftItems>
                <SwipeItems Mode="Reveal" SwipeBehaviorOnInvoked="Auto">
                    <SwipeItem
                        BackgroundColor="ForestGreen"
                        Command="{Binding SwipeToEditReminderCommand, Source={RelativeSource AncestorType={x:Type vm:ReminderPageViewModel}}}"
                        CommandParameter="{Binding . }"
                        IconImageSource="{StaticResource MenuEditIconWhite}"
                        Text="edit" />
                    <SwipeItem
                        BackgroundColor="Tomato"
                        Command="{Binding SwipeToDeleteReminderCommand, Source={RelativeSource AncestorType={x:Type vm:ReminderPageViewModel}}}"
                        CommandParameter="{Binding . }"
                        IconImageSource="{StaticResource MenuDeleteIconWhite}"
                        Text="delete" />
                </SwipeItems>
            </SwipeView.LeftItems>

            <!-- The Content -->

            <StackLayout
                Margin="12"
                Padding="18,12"
                Orientation="Horizontal"
                VerticalOptions="CenterAndExpand">
                <StackLayout Spacing="3">
                    <Label Text="{Binding ReminderName}" />
                    <Label>
                        <Label.FormattedText>
                            <FormattedString>
                                <Span Text="{Binding ReminderOnTimeLabel}" />
                                <Span Text=" - " TextColor="DimGray" />
                                <Span Text="{Binding ReminderOffTimeLabel}" />
                            </FormattedString>
                        </Label.FormattedText>
                    </Label>
                </StackLayout>
            </StackLayout>
        </SwipeView>
    </DataTemplate>
</CollectionView.ItemTemplate>
Developer technologies | .NET | .NET MAUI
Developer technologies | XAML
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. dg2k 1,416 Reputation points
    2023-06-29T18:51:47.3166667+00:00

    Now, having wasted considerable time, I can answer this question with 4 words:

    Do NOT Use Threshold.

    I used the Threshold property before and makes you think that it's useful (as it should, because it determines how much the content swipes from its rest position). But no, when used with CollectionView control under net7.0 or net8.0 it seems to be a trouble maker. Remove the Threshold property and everything will be as expected.

    Which leads me to comment that the Threshold property screwing up things this way must still be a bug.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.