如何在Android的Xamarin.Forms中的NavigationBar的左侧添加ToolbarItem? [英] How to add ToolbarItem on the left side of NavigationBar in Xamarin.Forms on Android?

查看:346
本文介绍了如何在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/

这篇关于如何在Android的Xamarin.Forms中的NavigationBar的左侧添加ToolbarItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆