2017-03-17 188 views
3

嘿傢伙我有一個程序,我現在在xamarin形式工作的一個xamarin形式是這樣的: enter image description here如何設置選項卡2在啓動選項卡頁面設置爲默認選項卡

當應用程序加載的朋友選項卡是加載的第一個選項卡,我應該如何將其設置爲應用程序啓動時要加載的第一個選項卡?

繼承人我的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(); 






     } 
    } 
} 

我搜索谷歌,所以我覺得是時候要問!

在此先感謝:)

回答

5

您可以訪問TabbedPage的孩子的枚舉,並推進其位置兩次,讓您的‘第二個選項卡’。將該頁分配爲您的CurrentPage

public HomePage() 
{ 
    InitializeComponent(); 
    var pages = Children.GetEnumerator(); 
    pages.MoveNext(); // First page 
    pages.MoveNext(); // Second page 
    CurrentPage = pages.Current; 
} 
+0

非常感謝您的支持! – Phoneswapshop

3

我認爲你必須設置「CurrentPage」屬性。

在代碼是一樣的東西

  TabbedPage tp = new TabbedPage(); 
      tp.Children.Add(new PageFriends()); 
      tp.Children.Add(new PageSnap()); 
      tp.Children.Add(new PageNotes()); 
      tp.CurrentPage = tp.Children[1]; 
+0

感謝您的回覆!我試過你的代碼示例,並且在最後一行代碼中出現此錯誤:錯誤CS0021:無法將[]的索引應用於類型爲'Xamarin.Forms.TabbedPage'(CS0021)的任何其他建議? – Phoneswapshop

+0

也許tp.Children [1]但我的只是一個使用代碼的示例。如果您使用xaml,我認爲您必須編寫其他內容才能將第二個選項卡分配給CurrentPage屬性 –

相關問題