6
votes

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?

3
Didn't notice any errors. Have you tried Clean->Rebuild solution? - Yehor Hromadskyi
I rebuild project 100 times but It doesn't display title. only label in stack layout is display. - RMR
Are you able to see NavigationBar in the top of page? - Yehor Hromadskyi
No, There is no any navigation bar. - RMR
Then you could try to use static method of NavigationPage.SetHasNavigationBar from documentation - Yehor Hromadskyi

3 Answers

4
votes

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

InitializeComponent();

MainPage = new NavigationPage(new Page2());
1
votes

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">
0
votes

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

[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());
    }
}