代码之家  ›  专栏  ›  技术社区  ›  fluter

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

  •  1
  • fluter  · 技术社区  · 7 年前

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

    选项卡式页面的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

    1 回复  |  直到 7 年前
        1
  •  1
  •   Steve Chadbourne    7 年前

    我想这是安卓上的?我不确定刷卡在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);
            }
        }
    }
    

    编辑

    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"