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

你离开我真会死。 提交于 2020-02-15 09:05:49

问题


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.

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?


回答1:


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://docs.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/



来源:https://stackoverflow.com/questions/52617416/how-to-add-toolbaritem-on-the-left-side-of-navigationbar-in-xamarin-forms-on-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!