44
votes

Haven't been able to find quite the right answer for this yet. I want to add a button into the navigation / title bar at the top of a Xamarin Forms Navigation Page. Note that I need to know a method that will work on android, I'm not interested in trying to find an iOS only solution here. This button needs to be an image button as I want a way to access a hamburger menu.

1
Could you please add some more detail about what you've tried already and any code snippets you've used?Paul Andrew
none of the code snippets I've tried have worked in the slightest, so I really have nothing to show.Jobalisk

1 Answers

79
votes

Use ToolbarItem from YourPage.xaml.cs:

ToolbarItems.Add(new ToolbarItem("Search", "search.png",() =>
{
  //logic code goes here
}));

In Xaml:

<ContentPage.ToolbarItems> 
    <ToolbarItem Icon="search.png" Text="Search" Clicked="Search_Clicked"/>
</ContentPage.ToolbarItems>

Update

Xamarin.Forms introduced TitleView in 3.2.0 that you can customize title of the navigation.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TestPage">
    <NavigationPage.TitleView>
        <Button ... />
    </NavigationPage.TitleView>
    ...
</ContentPage>