2017-05-04 95 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。如果您想查看,示例的链接也包含此示例。 –