2017-05-04 12 views
0

私はC#での経験はありますが、XamarinとXMLについてはかなり新しいです。私は、XMLでのタブ付きページを作成して、それがすべてMain.axmlで表示されていない:タブ付きページとコンテンツページが表示されない

<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.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'(not axml)を' App.xaml.cs'の 'MainPage'として設定していますか? –

+0

SetContentView(Resource.Layout.Main)を追加しました。エラーをスローしていますが、エラーがスローされているようです。TabbedPage – user7834940

答えて

0

MainActivity.csは、Xamarin Formsをサポートするように設定されておらず、ビューをネイティブにロードします。 MainActivity.csを次のように変更してください。

Android.Appを使用する。 012.Whatgetを使用している ; を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> 

あなたが例を参照したい場合は、外観を持つことができますat https://github.com/exrin/ExrinSample/blob/master/Exrin-Sample/ExrinSample.Droid/MainActivity.cs

+0

ありがとうございます。しかし、私のプロジェクトにはApp.xaml.csファイルも含まれていません。 – user7834940

+0

1つは、Applicationから継承されています。次に、MainPageプロパティにMainPageの新しいインスタンスを割り当てます。 Xamarin Formsアプリケーションのレイアウトを確認するには、最初から新しいXamarin Formsアプリケーションを作成します。 Xamarin Formsアプリケーションではなく、スタンドアローンのXamarin.Androidアプリだけを作成しました。この例へのリンクには、見たい場合の例も含まれています。 –

関連する問題