0

I declare my main page:

public App () {
    MainPage = new NavigationPage(new MainPage());
}

Then on main page open ContantPage after tapping a button:

class MainPage : ContentPage {
    public MainPage() {
        button.Clicked += to_my_contentpage;
        //...
    }

    private async void to_my_contentpage(object sender, EventArgs e) {
        await Navigation.PushModalAsync(new my_contentpage());
        //using PushAsync doesn't help
    }
}

And try to show button on this page as ToolbarItem:

public class my_contentpage : ContentPage {
    public my_contentpage () {
        ToolbarItem AddButton = new ToolbarItem("AddButton", "AddIcon.png", () => {
            Console.WriteLine("Clicked");
        });
        this.ToolbarItems.Add(new ToolbarItem());
        //...
        this.Content = new StackLayout { Children = { header, listView } };
    }
}

I feel like doing everithing according to this answer but my ToolbarItem is not included to my page: How do i add toolbar for android in xamarin,forms as ToolbarItem is not working for .droid?

What am I doing wrong?

Community
  • 1
  • 1
InfernumDeus
  • 1,185
  • 1
  • 11
  • 33
  • When adding a `ToolBarItem` it is required to use a `NavigationPage`. Did you try doing `await Navigation.PushModalAsync(new NavigationPage(new my_contentpage()));?` – Demitrian Jan 14 '17 at 12:43

1 Answers1

1

PushModalAsync is not going to work in this case, since you need to have a Navigation Bar in order to add ToolBarItems to it.

Since a Modal page explicitly does not show/contain a NavigationBar you are not going to be able to do it this way.

Solutions:

  1. Create a Custom NavigationBar and add any Views you need to it.
  2. Do not use a Modal Page.

Hope this helps.

Mario Galván
  • 3,964
  • 6
  • 29
  • 39