本文介绍了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 中的页面之间滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-25 05:46