android - 在 tabbedpage 的子页面的 segmentcontrol 内路由滑动操作

标签 android xamarin xamarin.forms swipe uisegmentedcontrol

所以我正在为跨平台应用程序使用 Xamarin 表单,主 UI 是一个选项卡式页面,其中一个页面有一个 segmented control。其中,段控件将切换 ListView 控件的数据。问题是当我滑动屏幕时,它会在标签页的不同子页面之间切换,但我希望它在子页面内的段控件之间切换。无论如何我可以让滑动不适用于标签页,但内部段控件?

标签页的 XAML:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:local="clr-namespace:MainApp"
        x:Class="MainApp.MainPage">
  <!--Pages can be added as references or inline-->
    <local:NewsPage Title="News" Icon="icon.png"/>
    <ContentPage Title="Guides" Icon="icon.png"/>
    <ContentPage Title="Wallets" Icon="icon.png"/>
    <ContentPage Title="Me" Icon="icon.png"/>
</TabbedPage>

新闻页面:

<controls:SegmentedControl x:Name="SegControl" TintColor="#007AFF" SelectedSegment="0"
                                       VerticalOptions="Center"
                                       Grid.Column="1" ValueChanged="SegControl_ValueChanged">
    <controls:SegmentedControl.Children>
        <controls:SegmentedControlOption Text="Type1" />
        <controls:SegmentedControlOption Text="Type2" />
    </controls:SegmentedControl.Children>
</controls:SegmentedControl>
<ListView ItemsSource="{Binding Source={StaticResource SArray}}" Grid.Row="1" Grid.Column="0" RowHeight="85">
 <ListView.ItemTemplate> ... </ListView>

effect

最佳答案

我认为这是在 Android 上?我不确定滑动是否适用于 iOS。

一个选项是禁用标签页上的滑动。

您可以使用自定义渲染器执行此操作。

[assembly: ExportRenderer(typeof(CustomTabbedPage), typeof(CustomTabbedPageRenderer))]
namespace App1.Droid
{
    public class CustomTabbedPageRenderer : TabbedPageRenderer
    {

        protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
        {

            var info = typeof(TabbedPageRenderer).GetTypeInfo();
            var fieldInfo = info.GetField("_useAnimations", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldInfo.SetValue(this, false);
            base.OnElementChanged(e);
        }
    }
}

编辑

看起来这已经添加到 Xamarin Forms 中了:

https://github.com/xamarin/Xamarin.Forms/pull/409

另一个编辑

还有另一种方式。我今天学到了很多东西!

public partial class MainPage : Xamarin.Forms.TabbedPage
{
    public MainPage()
    {
        InitializeComponent();

        this.On<Xamarin.Forms.PlatformConfiguration.Android>().SetIsSwipePagingEnabled(false);
    }
}

我正在努力

来自 XAML

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
        android:TabbedPage.IsSwipePagingEnabled="False"

关于android - 在 tabbedpage 的子页面的 segmentcontrol 内路由滑动操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46557677/

相关文章:

android - 检索项目 : No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar' . 的父项时出错 visual studio xamarin

android - 如何授予其他帐户访问 Google Play Developer Console 游戏服务页面的权限?

xamarin.ios - 使用 Xamarin.iOS 在 iOS 7 上的 ViewDidAppear 方法中显示被阻止的 UIAlertView 不起作用

ios - 如何使用 webview 在 Xamarin.iOS 中实现手动 Facebook 登录

ios - 如何在 IOS 中删除选择器边框

android - 为什么来自 Kotlin May 更新的新 LiveData 构建器在我的项目中不起作用

Android:如何获取 fragment 的 View

C# 异步任务不会继续

Xamarin.Forms 默认控件模板

c# - 如何将 Observable Collection 的 Item 属性绑定(bind)到 Switch 状态?