首页 文章

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

提问于
浏览
1

所以我使用Xamarin表单作为跨平台应用程序,主UI是一个标签页,其中一个页面中有一个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 回答

  • 1

    我认为这是在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"
    

相关问题