TabbedPage和Content页面未显示 [英] TabbedPage and Content pages are not showing
问题描述
尽管我有使用C#的经验,但我对Xamarin和XML还是比较陌生.我已经在xml中创建了一个选项卡式页面,它根本没有显示 Main.axml :
I am fairly new to Xamarin and XML although I have experience with C#. I have created a tabbed page in xml and it isn't displaying at all 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子级(主页"和添加位置"),我希望主页"是默认页面,尽管TabbedPage不会显示并且应用程序为空白.
I have 2 tabbedpage children (Home and Add Location) I want the Home page to be the default page, although even the TabbedPage won't show up and the app is blank.
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);
}
}
}
谢谢
马特
推荐答案
您的MainActivity.cs未设置为支持Xamarin Forms,它会原生加载视图.将您的MainActivity.cs更改为此:
Your MainActivity.cs isn't setup to support Xamarin Forms, its loading the view natively. Change your MainActivity.cs to this:
使用Android.App; 使用Android.Widget; 使用Android.OS;
using Android.App; using Android.Widget; using 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的文件,然后在其中添加此主题.
You will also need to create a file call styles.xml in your Resources > Values folder and add this theme in.
<?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
If you want to see an example you can have a look at https://github.com/exrin/ExrinSample/blob/master/Exrin-Sample/ExrinSample.Droid/MainActivity.cs
这篇关于TabbedPage和Content页面未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!