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);
};
}
}
}