Forms禁用TabbedPage中页面之间的滑动

Forms禁用TabbedPage中页面之间的滑动

本文介绍了Xamarin Forms禁用TabbedPage中页面之间的滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以禁用Xamarin Forms中Android上的TabbedPage之间的滑动?

Is there a way to disable the swiping between TabbedPage on Android in Xamarin Forms?

XAML:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App.MainTabbedPage">
</TabbedPage>

C#:

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace App
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainTabbedPage : TabbedPage
    {
        public MainTabbedPage ()
        {
            InitializeComponent();
            Children.Add(new PageOne());
            Children.Add(new PageTwo());
            Children.Add(new PageThree());
        }
    }
}

当前行为是,您只需滑动即可在页面之间进行切换.但是我想禁用它...我找到了此链接,但是我似乎无法在代码中实现它.任何帮助表示赞赏

Current behavior is that you can simply swipe to switch between the pages. But I'd like to disable that...I found this link but I can't seem to implement it in my code. Any help appreciated

推荐答案

您基本上有两个选择:使用代码隐藏"或XAML.我将在此答案中对两者进行描述.

You basically have two options: Either using Code Behind or XAML. I will describe both in this answer.

使用隐藏代码时,可以对任何给定的TabbedPage使用SetIsSwipePagingEnabled(bool)扩展方法:

When using Code Behind, you can use the SetIsSwipePagingEnabled(bool) extension method for any given TabbedPage:

namespace App
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainTabbedPage : TabbedPage
    {
        public MainTabbedPage ()
        {
            InitializeComponent();

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

            Children.Add(new PageOne());
            Children.Add(new PageTwo());
            Children.Add(new PageThree());
        }
    }
}

XAML

在XAML中,您可以像这样将TabbedPageIsSwipePagingEnabled属性设置为False:

XAML

In XAML, you can set the IsSwipePagingEnabled property of your TabbedPage to False like this:

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

其他详细信息可以在这篇文章中找到.

这篇关于Xamarin Forms禁用TabbedPage中页面之间的滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 05:26