首页 > 解决方案 > xamarin 表单:如何禁用选项卡按钮

问题描述

我有标签页,其中有 3 个标签,我需要启用=false 第 2 和第 3 个标签。当我完成第一页时,我需要像表单向导一样工作,然后应该启用第二个选项卡 = true,我已经尝试像下面这样的代码,但它不起作用

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            x:Name="maintab"
            x:Class="OnlineKIHStore.Views.CheckOuts" 
            BarBackgroundColor="#2F3C51" 
            Title="Checkout"
            BarTextColor="White">

        <ContentPage x:Name="first" Title="Login/Register" Icon="user"  IsEnabled="True">
            <StackLayout>
        </ContentPage>
        <ContentPage x:Name="second" Title="SHIPPING" Icon="shipping" IsEnabled="False">

        </ContentPage>
        <ContentPage x:Name="third" Title="Payment" Icon="payment" IsEnabled="False">

        </ContentPage>
</TabbedPage>

标签: xamarin.forms

解决方案


  • 如果您提到“enabled=false” - 您可以单击标签栏。它将加载页面,但不允许在该特定页面中执行任何操作。
  • 如果您提到“IsVisible="False"” - 您仍然可以单击标签栏。你只能看到一个空的屏幕。

一种方法 - 首先不要加载你想要的标签栏。完成第 1 页后,插入您需要的标签栏。

这是我根据您的代码的示例

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        x:Name="maintab"
        x:Class="OnlineKIHStore.Views.CheckOuts" 
        BarBackgroundColor="#2F3C51" 
        Title="Checkout"
        BarTextColor="White">
<TabbedPage.Children>
    <firstPage Title="Login/Register" Icon="user"/>
    <thirdPage Title="Payment" Icon="payment"/>
</TabbedPage.Children>

在 .CS 文件中

public CheckOuts 
{ 
  InitializeComponent();
if(check_finished_pageone)
 {
    Children.Insert(2, new SecondPage { Title = "SHIPPING", Icon = "shipping" });
}}

完成 page1 后,重新加载标签页。因此,现在将添加带有新标签栏的第二页。

另一种方法是单击第 2 页后,您可以导航到第 1 页,提示用户完成第 1 页

e<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        x:Name="maintab"
        x:Class="OnlineKIHStore.Views.CheckOuts" 
        BarBackgroundColor="#2F3C51" 
        Title="Checkout"
        CurrentPageChanged="TabbedPage_CurrentPageChanged"
        BarTextColor="White">

.CS 文件

private async void TabbedPage_CurrentPageChanged(object sender, EventArgs e){
 var i = this.Children.IndexOf(this.CurrentPage);
 if (i == 2)
{
     await App.Current.MainPage.DisplayAlert("Error", "You have to finish the page one before navigating this page", "Ok"))
     this.CurrentPage = this.Children[0];
 }}

此方法允许您单击第二个标签栏,但它会再次重定向到第 1 页。


推荐阅读