Xamarin:在Android导航上覆盖PushAsync

时间:2018-11-27 10:26:15

标签: xamarin navigation custom-renderer

在我的应用程序中,我创建了呈现的自定义导航,重写了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?

Tx

1 个答案:

答案 0 :(得分:1)

您可以在Android渲染器中override使用这些方法来推送和弹出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);    
    }
}