简体   繁体   中英

Page Title doesn't display in Xamarin.Forms project

I am working on Xamarin.Forms.

When I created blank Xamarin.Forms project there are four project created in one solution, one for iOS, one for Android, one for Windows and one is the Portable project (Common Project).

I add one XAML form named "Page2.XAML" with this code:

<?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="Rutul_App.Page2"
             Title="aaaa">
    <ContentPage.Content>
        <StackLayout>
            <Label Text="ABC" HorizontalOptions="Center"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

and in the code behind file:

namespace Rutul_App
{
    public partial class Page2 : ContentPage
    {
        public Page2()
        {
            InitializeComponent();
        }
    }
}

In App.cs page I have added:

public App()
    {
        // The root page of your application
        MainPage = new NavigationPage(new Page2());
    }

Problem :

My problem is that the title and the BackGroundImage don't display. There are so many property that doesn't work.

My page is inherit form ContentPage but I can't access property of the ContentPage class. Properties are public.

Why is my title not being displayed?

You can define the page as NavigationPage in App.xaml.cs, without declaring NavigationPage in the xaml file, ie like so in App.xaml.cs:

InitializeComponent();

MainPage = new NavigationPage(new Page2());

Try

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Rutul_App.Page2"
             Title="aaaa" NavigationPage.HasNavigationBar="True">

If above answers didn't worked then just be sure that you are keeping your MainActivity.cs and styles.xml with default values. eg

[Activity(Label = "SMSMobile.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = false, NoHistory = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
        base.OnCreate(bundle);
        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM