微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。