如何在Android的Xamarin.Forms中的NavigationBar的左侧添加ToolbarItem?
我需要要有关闭按钮(在这种情况下)导航栏的左侧 , 如下.我仅在弹出窗口中需要它,因此其他元素/导航没有潜在的问题.
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.
Google对此有一些建议,但我只看到了iOS示例(在iOS custom renderer
中处理起来不是一件大事),但没有任何提示(轻松处理) >)和 Android .
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.
只需清楚一点,Xamarin.Forms
需要与此定义类似的代码(或隐藏代码):
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>
有什么想法吗?
使用Xamarin Forms 3.2,可以使用NavigationBar
来处理更复杂场景的新方法.它叫做TitleView
.
With Xamarin Forms 3.2 there is a new way of handling more complex scenario's with the NavigationBar
. It's called the TitleView
.
使用此按钮,您可以将所需的任何View
推入NavigationBar
.
With this you can push any View
you want unto the NavigationBar
.
示例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>
有关此的更多信息 https://docs.microsoft.com/zh-cn/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical#displaying-views-in-the-navigation-bar 并找到示例项目此处 https://developer.xamarin.com/samples/xamarin-forms/Navigation /TitleView/
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/