Xamarin表单导航后退按钮 [英] Xamarin forms navigation back button

查看:75
本文介绍了Xamarin表单导航后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是xamarin表单应用程序开发的新手,目前,我在覆盖工具栏的后退按钮onclick时遇到问题.在ios中,我可以实现,但是在android中,它无法正常工作,任何人都可以帮助我解决如何在我的项目中实现此目标.

I am a newbie in xamarin forms app development, currently, I am facing an issue in overriding the toolbar back button onclick. In ios, I am able to achieve but in android its not working can anyone help me out on how to achieve this in my project.

推荐答案

默认情况下,它仅适用于iOS和 Android物理后退按钮.如果您还希望支持导航栏按钮,则需要使用自定义平台逻辑.看一下这篇博客文章:让替代导航栏"后退按钮在Xamarin For中单击.他使用后退按钮的自定义操作创建了一个公共内容页面:

By default it works on iOS and on Android physical back button only. If you want to also support the navigation bar button, you need to use custom platform logic. Take a look on this blog post: Let’s Override Navigation Bar back button click in Xamarin For. He creates a common content page with custom action for back button:

 public class CoolContentPage : ContentPage
    {
        /// <summary>
        /// Gets or Sets the Back button click overriden custom action
        /// </summary>
        public Action CustomBackButtonAction { get; set; }

        public static readonly BindableProperty EnableBackButtonOverrideProperty =
               BindableProperty.Create(
               nameof(EnableBackButtonOverride),
               typeof(bool),
               typeof(CoolContentPage),
               false);

        /// <summary>
        /// Gets or Sets Custom Back button overriding state
        /// </summary>
        public bool EnableBackButtonOverride
        {
            get
            {
                return (bool)GetValue(EnableBackButtonOverrideProperty);
            }
            set
            {
                SetValue(EnableBackButtonOverrideProperty, value);
            }
        }
    }

然后他在Anroid代码的 OnOptionsItemSelected 方法内调用 CustomBackAction .

And then he calls CustomBackAction inside OnOptionsItemSelected method in Anroid code.

这篇关于Xamarin表单导航后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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