【问题标题】:XamarinForms: how use a Custom Navigation PageXamarin Forms:如何使用自定义导航页面
【发布时间】:2018-11-16 07:55:46
【问题描述】:

我要求在我的应用程序的特定视图上进行自定义导航, 我创建了一个自定义导航 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();
        ...

【问题讨论】:

    标签: xamarin navigation customization


    【解决方案1】:

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

    没有,你可以参考下面的代码。

    例如

    在 App.cs 中创建根页面

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

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

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

    【讨论】:

    • 德克萨斯州。当前上下文中不存在子项
    • 这是一个标签页而不是一个内容页
    • 我的不是标签页
    猜你喜欢
    • 1970-01-01
    • 2018-07-07
    • 2021-02-24
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多