How to change backGround color in Xamarin forms NavigationPage

后端 未结 4 747
北恋
北恋 2021-01-05 15:54

I\'m trying to change the background color of navigationBar in navigationPage I\'m using this code`using System;

using System;
using Xamarin.Forms;
using Sys         


        
4条回答
  •  执念已碎
    2021-01-05 16:49

    If you want to change the NavigationBar BackgroundColor on each page with a different color. You can do the following on the Codebehinds of each page/view.

    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;
    
    namespace NewApp.Cross.Views
    {
        [XamlCompilation(XamlCompilationOptions.Compile)]
        public partial class NewView : ContentPage
        {
            public NewView()
            {
                InitializeComponent();
                Title = "PageTitle"
    
                NavigationPage.SetHasBackButton(this, false);
    
                ((NavigationPage)Application.Current.MainPage).BarBackgroundColor = Color.Black;
                ((NavigationPage)Application.Current.MainPage).BarTextColor = Color.OrangeRed;
            }
        }
    }
    

    It works on Android and iOS.

提交回复
热议问题