XamarinForms:如何使用自定义导航页面

时间:2018-11-16 07:55:46

标签: xamarin navigation customization

我要在应用程序的特定视图上进行皮肤导航, 我创建了一个自定义导航ios:

public class CustomNavigationPageRenderer : NavigationRenderer
    {
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
            UINavigationBar.Appearance.ShadowImage = new UIImage();
            UINavigationBar.Appearance.BackgroundColor = UIColor.Clear;
            UINavigationBar.Appearance.TintColor = UIColor.White;
            UINavigationBar.Appearance.BarTintColor = UIColor.Clear;
            UINavigationBar.Appearance.Translucent = true;
        }
    }

和一个通用的接口类:

public partial class CustomPage : NavigationPage
    {
        public CustomPage(): base()
        {
            InitializeComponent();
        }

        public CustomPage(Page root) : base(root)
        {
            InitializeComponent();
        }

        public bool IgnoreLayoutChange { get; set; } = false;

        protected override void OnSizeAllocated(double width, double height)
        {
            if (!IgnoreLayoutChange)
                base.OnSizeAllocated(width, height);
        }
    }

现在,在我看来,我该如何使用它? 我需要将原始导航设置为false吗? (NavigationPage.SetHasNavigationBar(this,false);)

public MySpecificViewNeedCustoNAv()
        {

        CustomPage myNavigationPage = new CustomPage();
        ...

1 个答案:

答案 0 :(得分:0)

  

是否需要将原始导航设置为false?

否,您可以参考以下代码。

例如

  

在App.cs中创建根页面

public App ()
{
  MainPage = new CustomPage (new xxxpage());
}
  

将页面推送到页面的导航堆栈中

async void ButtonClicked (object sender, EventArgs e)
{
  await Navigation.PushAsync (new xxxpage());
}