Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add ToolbarItem on the left side of NavigationBar in Xamarin.Forms on Android?

I need to have a close button (in this particular case) on the left of Navigation Bar, as below. I need it only for popups, so there is no potential issues with other elements/navigations.

enter image description here

There are a few suggestions in Google regarding this, but I saw only iOS examples (and this is not a big thing to handle in iOS custom renderer), but no hints how to handle it (easily) with Android.

Just to be clear, it need it for Xamarin.Forms defining similar to this (or codebehind):

<ContentPage.ToolbarItems>
    <ToolbarItem Text="X" Priority="-1" Command="{Binding GoCancel}"/>
    <ToolbarItem Icon="icon_save" Command="{Binding GoSave}"/>
</ContentPage.ToolbarItems>

Any thoughts?

like image 554
Agat Avatar asked Oct 02 '18 22:10

Agat


1 Answers

With Xamarin Forms 3.2 there is a new way of handling more complex scenario's with the NavigationBar. It's called the TitleView.

With this you can push any View you want unto the NavigationBar.

Example XAML:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="NavigationPageTitleView.TitleViewPage">
    <NavigationPage.TitleView>
        <Slider HeightRequest="44" WidthRequest="300" />
    </NavigationPage.TitleView>
    ...
</ContentPage>

More info about it here https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical#displaying-views-in-the-navigation-bar and example project can be found here https://developer.xamarin.com/samples/xamarin-forms/Navigation/TitleView/

like image 195
Depechie Avatar answered Oct 13 '22 21:10

Depechie