Xamarin:覆盖 Android 导航上的 PushAsync

Xamarin: override PushAsync on Android navigation

在我的应用程序中,我创建了一个呈现的自定义导航,OnPushAsync 和 PopViewController 被覆盖并且它适用于 iOS。

public class NavRenderer : NavigationRenderer
            {
                protected override async Task<bool> OnPushAsync(Page page, bool animated)
                { ...
    }


    public override UIViewController PopViewController(bool animated)
    {
        ....
        return base.PopViewController(false); 
    }

尝试在 Android 上做同样的事情(?),如何覆盖 OnPushAsync 和 PopViewController?

发送

您可以 override android 渲染器中的这些方法来推送和弹出 Pages

public class NavRenderer : NavigationRenderer
{
    public NavRenderer(Context context) : base(context)
    {

    }
    protected override Task<bool> OnPushAsync(Page view, bool animated)
    {
        return base.OnPushAsync(view, animated);
    }
    protected override Task<bool> OnPopViewAsync(Page page, bool animated)
    {
        return base.OnPopViewAsync(page, animated);
    }
}

这些是 iOS 渲染器中推入和弹出的等效方法 Controllers

public class NavRenderer : NavigationRenderer
{
    public override void PushViewController(UIViewController viewController, bool animated)
    {
        base.PushViewController(viewController, animated);
    }

    public override UIViewController PopViewController(bool animated)
    {
        return base.PopViewController(animated);    
    }
}