Skip to content

Instantly share code, notes, and snippets.

@rc1021
Created March 3, 2017 07:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rc1021/c2ed3e4f53c939bd3a2a64c400d682e9 to your computer and use it in GitHub Desktop.
Save rc1021/c2ed3e4f53c939bd3a2a64c400d682e9 to your computer and use it in GitHub Desktop.
How to: NavigationPage in XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App1.Pages"
x:Class="App1.CustomerPage">
<Label Text="Say something here..."/>
</ContentPage>
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace App1
{
public partial class CustomerNavigationPage : NavigationPage
{
public CustomerNavigationPage() : base(new CustomerPage()) { }
}
public partial class CustomerPage : ContentPage
{
public CustomerPage()
{
InitializeComponent();
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App1"
x:Class="App1.MainPage">
<local:CustomerNavigationPage
Title="Navigation Title"
BackgroundColor="#f0f0f0"/>
</TabbedPage>
@UchiTesting
Copy link

Hi,
Thank you for the proposition but I just tried it and it does not work here.
I get this error message.
Error XLS0503 A value of type 'NavigationPickerNavigationPage' cannot be added to a collection or dictionary of type 'IList`1'. FormsControls MainPage.xaml 11

My code (NavigationPicker.xaml.cs) :

namespace FormsControls.Views
{
    public partial class NavigationPickerNavigationPage : NavigationPage
    {
        // To put the current page into NavigationPage
        public NavigationPickerNavigationPage() : base(new NavigationPicker()) { }
    }

    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class NavigationPicker : ContentPage
    {
        public NavigationPicker()
        {
            InitializeComponent();
        }

        private async void ViewCell_Tapped(object sender, EventArgs e)
        {
            var page = new NavigationPickerDetail();
            page.ContactMethods.ItemSelected += (source, args) =>
            {
                contactMethod.Text = args.SelectedItem.ToString();
                Navigation.PopAsync();
            };
            await Navigation.PushAsync(page);
        }
    }
}

It is in the same namespace as the NavigationPicker ContentPage so in my MainPage which is a CarouselPage, I should be able to add the NavigationPickerNavigationPage but it doesn't show in IntelliSense list at all.
Compiling works. Application run but it is simply ignored. The code does not know of this NavigationPickerNavigationPage class.
Just see the screenshot below:
image

One thing I find weird is using the partial keyword where there is no other part to that NavigationPage derived class. You didn't seem to have made a XAML view to it. Could it be the reason why it does not work ?
I also tried and it does not make any difference.
Kind regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment