public HomePage()
        {
            // Define command for the items in the TableView.
            Command <Type> navigateCommand =
                new Command <Type>(async(Type pageType) =>
            {
                Page page = (Page)Activator.CreateInstance(pageType);
                await this.Navigation.PushAsync(page);
            });

            Command newContactCommand =
                new Command(async() =>
            {
                Page page = new NewContactPage(null);
                await this.Navigation.PushAsync(page);
            });


            this.Title   = "Forms Gallery";
            this.Content = new TableView
            {
                Intent = TableIntent.Menu,
                Root   = new TableRoot
                {
                    new TableSection("Views for Presentation")
                    {
//                            new TextCell
//                            {
//                                Text = "Label",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(LabelDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "Image",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(ImageDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "BoxView",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(BoxViewDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "WebView",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(WebViewDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "Map",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(MapDemoPage)
//                            }
//                        },
//
//                        new TableSection("Views that Initiate Commands")
//                        {
//                            new TextCell
//                            {
//                                Text = "Button",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(ButtonDemoPage)
//                            },
////
//                            new TextCell
//                            {
//                                Text = "SearchBar",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(SearchBarDemoPage)
//                            }
//                        },
//
//                        new TableSection("Views for Common Data Types")
//                        {
//                            new TextCell
//                            {
//                                Text = "Slider (double)",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(SliderDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "Stepper (double)",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(StepperDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "Switch (bool)",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(SwitchDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "DatePicker",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(DatePickerDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "TimePicker",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(TimePickerDemoPage)
//                            },
//                        },
//
//                        new TableSection("Views for Editing Text")
//                        {
//                            new TextCell
//                            {
//                                Text = "Entry (single line)",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(EntryDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "Editor (multiple lines)",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(EditorDemoPage)
//                            }
//                        },
//
//                        new TableSection("Views to Indicate Activity")
//                        {
//                            new TextCell
//                            {
//                                Text = "ActivityIndicator",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(ActivityIndicatorDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "ProgressBar",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(ProgressBarDemoPage)
//                            }
//                        },
//
//                        new TableSection("Views that Display Collections")
//                        {
                        new TextCell
                        {
                            Text             = "Picker",
                            Command          = navigateCommand,
                            CommandParameter = typeof(PickerDemoPage)
                        },
//
//                            new TextCell
//                            {
//                                Text = "ListView",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(ListViewDemoPage)
//                            },

//                            new TextCell
//                            {
//                                Text = "TableView for a menu",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(TableViewMenuDemoPage)
//                            },
//
                        new TextCell
                        {
                            Text    = "New Contact",
                            Command = newContactCommand
                        },
//                        },
//
//                        new TableSection("Cells")
//                        {
//                            new TextCell
//                            {
//                                Text = "TextCell",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(TextCellDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "ImageCell",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(ImageCellDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "SwitchCell",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(SwitchCellDemoPage)
//                            },
//
//                            new TextCell
//                            {
//                                Text = "EntryCell",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(EntryCellDemoPage)
//                            }
//                        },
//
//                        new TableSection("Layouts with Single Content")
//                        {
//                            new TextCell
//                            {
//                                Text = "ContentView",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(ContentViewDemoPage)
//                            },
//                            new TextCell
//                            {
//                                Text = "Frame",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(FrameDemoPage)
//                            },
//                            new TextCell
//                            {
//                                Text = "ScrollView",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(ScrollViewDemoPage)
//                            }
//                        },
//
//                        new TableSection("Layouts with Multiple Children")
//                        {
//                            new TextCell
//                            {
//                                Text = "StackLayout",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(StackLayoutDemoPage)
//                            },
//                            new TextCell
//                            {
//                                Text = "AbsoluteLayout",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(AbsoluteLayoutDemoPage)
//                            },
//                            new TextCell
//                            {
//                                Text = "Grid",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(GridDemoPage)
//                            },
//                            new TextCell
//                            {
//                                Text = "RelativeLayout",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(RelativeLayoutDemoPage)
//                            }
//                        },
//
//                        new TableSection("Pages")
//                        {
//                            new TextCell
//                            {
//                                Text = "ContentPage",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(ContentPageDemoPage)
//                            },
//                            new TextCell
//                            {
//                                Text = "NavigationPage",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(NavigationPageDemoPage)
//                            },
//                            new TextCell
//                            {
//                                Text = "MasterDetailPage",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(MasterDetailPageDemoPage)
//                            },
//                            new TextCell
//                            {
//                                Text = "TabbedPage",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(TabbedPageDemoPage)
//                            },
//                            new TextCell
//                            {
//                                Text = "CarouselPage",
//                                Command = navigateCommand,
//                                CommandParameter = typeof(CarouselPageDemoPage)
//                            }
                    }
                }
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormsGallery.NewContactPage"/> class.
        /// </summary>
        /// <param name="parentRecord">Allows a parent record to be set. Use null if there is no parent.</param>
        public NewContactPage(AbstractRecord parentRecord)
        {
            this.parentRecord = parentRecord;
            this.contact      = new Contact {
                Notes = ""
            };

            Command <Type> notesEditorCommand =
                new Command <Type>(async(Type pageType) =>
            {
                NotesEditorPage page = (NotesEditorPage)Activator.CreateInstance(pageType, this.contact);
                await this.Navigation.PushAsync(page);
                this.notesCell.Detail = this.contact.Notes;
            });

            // Contact (General Information)
            Label contactHeader = new Label
            {
                Text = "Contact",
                Font = Font.SystemFontOfSize(30, FontAttributes.Bold),
                HorizontalOptions = LayoutOptions.Center
            };

            this.companyNameCell = new EntryCell    {
                Label = "Company Name"
            };
            this.titleCell = new EntryCell                  {
                Label = "Title"
            };
            this.firstNameCell = new EntryCell              {
                Label = "First Name"
            };
            this.lastNameCell = new EntryCell               {
                Label = "Last Name"
            };
            this.jobTitleRoleCell = new EntryCell   {
                Label = "Job Title / Role"
            };
            this.sourceCell = new EntryCell                 {
                Label = "Source"
            };
            this.companyCell = new SwitchCell               {
                Text = "Company"
            };
            this.notesCell = new TextCell
            {
                Text             = "Notes",
                Detail           = contact.Notes,
                Command          = notesEditorCommand,
                CommandParameter = typeof(NotesEditorPage)
            };

            this.detailsSection = new TableSection("Contact");
            this.detailsView    = new TableView
            {
                Intent = TableIntent.Form,
                Root   = new TableRoot("Details")
                {
                    detailsSection
                }
            };

            companyCell.OnChanged += (object sender, ToggledEventArgs e) => { ChangeCompanyMode(this.companyCell.On); };

            // Linked Records
            Command addNewRecordCommand =
                new Command(async() =>
            {
                string action = await DisplayActionSheet(null, "Cancel", null, "Contact", "Shoot", "Quote", "Sale");
                if (action == "Contact")
                {
                    var page = new NewContactPage(this.contact);
                    await this.Navigation.PushAsync(page);
                }
            });
            Command addExistingRecordCommand =
                new Command(async() =>
            {
                string action = await DisplayActionSheet(null, "Cancel", null, "Contact", "Shoot", "Quote", "Sale");
                if (action == "Contact")
                {
                    var page = new AddExistingRecordPage(RecordType.Contact, this.contact);
                    await this.Navigation.PushAsync(page);
                }
            });

            this.linkedRecordsSection = new TableSection("Linked Records");
            this.addNewLinkCell       = new TextCell {
                Text = "Add New", Command = addNewRecordCommand
            };
            this.addExistingLinkCell = new TextCell {
                Text = "Add Existing", Command = addExistingRecordCommand
            };

            PopulateLinkedRecordsSection();
            this.detailsView.Root.Add(this.linkedRecordsSection);

            // Build the page.
            this.Content = new StackLayout
            {
                Children = { contactHeader, detailsView }
            };

            ChangeCompanyMode(this.companyCell.On);
        }