Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Set global navigation controller colour

$
0
0

I am following along a starting (not very good) 'how to' course on using Xmarin and the instructors code is quite repetitive.
The colours for the navigation controller are defined individually in each controller class as below.

What I want to do is extract this into something like a partial in order to define it just once.
What is considered the best practice method of doing this? Creating helper classes or is there another way.

    namespace NoteTaker.iOS
    {
        partial class MainViewController : UIViewController
        {
            public MainViewController (IntPtr handle) : base (handle)
            {
            }

            public override void ViewDidLoad ()
            {
                base.ViewDidLoad ();

                // This is an example of code that is being repeated in different controllers
                this.NavigationController.NavigationBar.BarTintColor = UIColor.FromRGB (255,0,255);
                this.Title = "Notes";
                this.NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes () { ForegroundColor = UIColor.White };

                var table = new UITableView () {
                    Frame = new CoreGraphics.CGRect (0, this.NavigationController.NavigationBar.Frame.Bottom, this.View.Bounds.Width, this.View.Bounds.Height - this.NavigationController.NavigationBar.Frame.Height),
                };
                this.View.Add (table);

                var addButton = new UIBarButtonItem (UIBarButtonSystemItem.Add);
                addButton.TintColor = UIColor.White;

                this.NavigationItem.RightBarButtonItems = new UIBarButtonItem[] { addButton };
                addButton.Clicked += (sender, e) => {
                    Console.WriteLine ("Button clicked");
                    this.NavigationController.PushViewController (new AddNoteViewController(), true);
                };

            }
        }
    }

Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>