Xamarin-滑动嵌套的可滑动元素时如何阻止SwipeView移动?

问题描述

我在Xamarin表单项目中有一个swipeview,其中包含一个ListView,其代码如下:

<swipeview Margin="0,0" Padding="0" x:Name="Mainswipeview" BackgroundColor="Transparent"
                       Swipestarted="Swipestarted" SwipeEnded="SwipeEnded" SwipeChanging="SwipeChanging" CloseRequested="SideMenuClosed" VerticalOptions="FillAndExpand" Rotation="180">

    <Grid x:Name="swipeContent" VerticalOptions="FillAndExpand">
                                

        <ListView x:Name="reportsList" HasUnevenRows="True" Footer="" SeparatorColor="Transparent" BackgroundColor="White" VerticalOptions="CenterandExpand"
                               CachingStrategy="RetainElement" ItemsSource="{Binding AllReports}" Margin="20" ItemTapped="Handle_ItemTapped"
                               IsVisible="{Binding IsEmptyReports,Converter={StaticResource inverseBoolConverter}}">
            <ListView.ItemTemplate>

                <DataTemplate>
                                
                    <ViewCell>
                        <ViewCell.ContextActions>
                            <MenuItem Clicked="OnRename"
                                                    CommandParameter="{Binding .}"
                                                    Text="Rename"  />
                            <MenuItem Clicked="OnDelete"
                                                    CommandParameter="{Binding .}"
                                                    Text="Delete" IsDestructive="True" />
                        </ViewCell.ContextActions>

                             Remaining view content

                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

    </Grid>

    <swipeview.LeftItems VerticalOptions="FillAndExpand" >
                        
         Menu code here


    </swipeview.LeftItems>
</swipeview>

swipeviewLeftItems实际上位于应用程序的右侧,因为我将视图旋转了180度(这是为了修复错误,并且与该问题无关)。这意味着向左滑动会显示右侧的项目。

这在Android上工作正常,但是在IOS中,ContextActions元素的ViewCell包含可滚动菜单。这意味着当我尝试在ListView元素内向左滚动以获取菜单”按钮时,滑动视图也开始向左移动,从而导致出现以下屏幕截图。

enter image description here

是否有办法阻止这种情况的发生,以便每当我在ListView元素之一中滑动时,swipeview都不会像这样移动?

enter image description here

我一直在探索以下想法,但还没有开始起作用:

  1. 使用TouchEffect在手指在列表视图上向下滑动时触发事件以取消滑动视图滑动(似乎没有方法属性可以在滑动视图上取消滑动)。

  2. 当手指触摸列表视图时,使swipeview不可滑动(除了设置IsEnabled = false;以外,似乎没有其他方法可以这样做,但这并不能阻止从并禁用swipeview中的所有内容包括ListView元素。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)