xamarin.forms - 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>
解决方案
- 如果您提到“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 页。
推荐阅读
- python-3.x - 在数据框上使用替换后防止列名消失
- python - 如何在 Bokeh 中仅绘制一个 Band?
- pdf - 如何修复 odoo 报告缺少 PDF 布局?
- r - 两个数据框的特定连接
- python - 使用 List 使用 Matplotlib 绘图 - 日期时间 - 格式上的不同行为
- java - Firestore:如何在 Firestore 中创建子集合而无需添加文档
- xml - bash 从元素中提取多个属性值 - XML
- typescript - Typescript 控制流分析无法识别已知类型
- sql-server - 将 TIMESTAMP 列从 Oracle 移动到 SQL Server
- python - 如何使用 FirefoxProfile 或 FirefoxOptions 通过 Selenium 设置 Firefox 浏览器的窗口位置