问题
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