gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:41 26 4
gpt4 key购买 nike

有没有办法在 Xamarin Forms 中禁用 Android 上 TabbedPage 之间的滑动?

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());
}
}
}

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

最佳答案

您基本上有两个选择:使用代码隐藏或 XAML。我将在这个答案中描述两者。

代码隐藏

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

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,如下所示:

<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"

更多详细信息可以在 this post 中找到.

关于android - Xamarin Forms禁用TabbedPage中页面之间的滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45820704/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com