我有一个正在使用 xamarin 形式的应用程序,它看起来像这样:
当应用程序加载好友选项卡是第一个要加载的选项卡时,如何在应用程序启动时将其设置为要加载的第一个选项卡?
这是我的 xaml 代码:
<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AppName;assembly=AppName"
x:Class="AppName.HomePage">
<TabbedPage.Children>
<NavigationPage x:Name="Friends" Title="Friends" Icon="firendstab.png">
<x:Arguments>
<local:FriendPage />
</x:Arguments>
</NavigationPage >
<NavigationPage x:Name="Snap" Title="Snap" Icon="snaptab.png">>
<x:Arguments>
<local:CameraPage />
</x:Arguments>
</NavigationPage>
<NavigationPage x:Name="Notes" Title="Notes" Icon="notetab.png">
<x:Arguments>
<local:NotePage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
继承人我的代码背后:using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace AppName
{
public partial class HomePage : TabbedPage
{
public HomePage()
{
InitializeComponent();
}
}
}
过去 2 天我在谷歌上搜索过,所以我想是时候问了!
最佳答案
您可以访问 TabbedPage
的枚举器的 child 并将其位置推进两次以获得您的“第二个标签”。将该页面指定为您的 CurrentPage
:
public HomePage()
{
InitializeComponent();
var pages = Children.GetEnumerator();
pages.MoveNext(); // First page
pages.MoveNext(); // Second page
CurrentPage = pages.Current;
}
关于xaml - 如何将 xamarin 表单中的选项卡 2 设置为启动时的默认选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42863886/