2017-05-04 98 views
0

雖然我有C#的經驗,但對Xamarin和XML我還是比較新的。我創建一個XML格式的標籤頁,它是不是在顯示所有Main.axmlTabbedPage和內容頁面不顯示

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:mypages="clr-namespace:MainActivity.Pages;assembly=MainActivity" 
      x:Class="MainActivity.tabPages"> 
    <TabbedPage.Children> 

    <mypages:Home /> 
    <mypages:AddLocation /> 

    </TabbedPage.Children> 
</TabbedPage> 

我有2個孩子tabbedpage(Home和添加位置)我要主頁是默認頁面,雖然即使TabbedPage也不會顯示,應用程序是空白的。

Home.axml

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="MainActivity.ActualPage" Title="Home" BackgroundColor="Green"> 
    <ContentPage.Content> 

    <Label Text="Hi there from Page 1" TextColor="White" Font="20" 
     VerticalOptions="Center" HorizontalOptions="Center" /> 

    </ContentPage.Content> 
</ContentPage> 

MainActivity.cs:

using Android.App; 
using Android.Widget; 
using Android.OS; 

namespace Xonify 
{ 
    [Activity(Label = "App", MainLauncher = true, Icon = "@drawable/icon")] 
    public class MainActivity : Activity 
    { 
     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 
      SetContentView (Resource.Layout.Main); 
     } 
    } 
} 

Project's Strucutre

感謝,

馬特

+0

請發佈您的完整代碼 – Pehlaj

+0

您是否將'Main.xaml'(而不是axml)設置爲'App.xaml.cs'中的'MainPage'? –

+0

我加了SetContentView(Resource.Layout.Main);它似乎已經添加了它,雖然它是拋出錯誤錯誤膨脹類TabbedPage – user7834940

回答

0

您的MainActivity.cs未安裝爲支持Xamarin Forms,其本機加載視圖。將您的MainActivity.cs更改爲:

using Android.App;使用Android.Widget的 ; 使用Android.OS;

namespace Xonify 
{ 
    [Activity(Label = "App", MainLauncher = true, Theme = "@style/MainTheme", Icon = "@drawable/icon")] 
    public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity 
    { 
     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 
      Forms.Init(this, bundle); 
      LoadApplication(new Xonify.PCL.App()); // Change to point to your App.xaml.cs class 
     } 
    } 
} 

您還需要建立在你的資源文件調用styles.xml>值文件夾,並在添加此主題。

<?xml version="1.0" encoding="utf-8" ?> 
<resources> 
    <style name="MainTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- You can change options in here, or change the parent style --> 
    </style> 
</resources> 

如果你想看到一個例子,你可以去看看在https://github.com/exrin/ExrinSample/blob/master/Exrin-Sample/ExrinSample.Droid/MainActivity.cs

+0

謝謝,但我的項目甚至沒有包含一個App.xaml.cs文件 – user7834940

+0

然後創建一個,從應用程序繼承。然後爲MainPage屬性分配一個新的MainPage實例。如果你想看看它的佈局如何,從頭開始創建一個新的Xamarin Forms應用程序。你已經創建了一個獨立的Xamarin.Android應用程序,而不是Xamarin Forms。如果您想查看,示例的鏈接也包含此示例。 –