// Constructor that takes a picker for defining new statistics.
        public ChooseStatisticOverlay(CGRect frame, nfloat transparency, UIColor color, UIPickerView statPicker) : base(frame)
        {
            // Store the statistics picker.
            var statisticPicker = statPicker;

            // Create a semi-transparent overlay with the specified background color.
            BackgroundColor = color;
            Alpha           = transparency;

            // Set the total height and width of the control set.
            nfloat totalHeight = 400;
            nfloat totalWidth  = 320;

            // Find the bottom x and y of the view.
            nfloat centerX = Frame.Width / 2;
            nfloat centerY = Frame.Bottom - 40;

            // Find the start x and y for the control layout (aligned to the bottom of the view).
            nfloat controlX = centerX - totalWidth / 2;
            nfloat controlY = centerY - totalHeight;

            // Toolbar with "Add" and "Done" buttons.
            UIToolbar toolbar = new UIToolbar
            {
                BarStyle    = UIBarStyle.Black,
                Translucent = false
            };

            toolbar.SizeToFit();

            // Add Button (add the new stat and don't dismiss the UI).
            UIBarButtonItem addButton = new UIBarButtonItem("Add", UIBarButtonItemStyle.Done, (s, e) =>
            {
                // Get the selected StatisticDefinition.
                StatDefinitionModel statPickerModel   = statisticPicker.Model as StatDefinitionModel;
                StatisticDefinition newStatDefinition = statPickerModel.SelectedStatDefinition;
                if (newStatDefinition != null)
                {
                    // Fire the OnMapInfoEntered event and provide the statistic definition.
                    OnStatisticDefined?.Invoke(this, newStatDefinition);
                }
            });

            // Done Button (dismiss the UI, don't use the selected statistic).
            UIBarButtonItem doneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Plain, (s, e) => { OnCanceled.Invoke(this, null); });

            // Add the buttons to the toolbar.
            toolbar.SetItems(new[] { addButton, doneButton }, true);

            // Define the location of the statistic picker.
            controlY = controlY + 200;
            statisticPicker.Frame = new CGRect(controlX, controlY, totalWidth, 200);

            // Set the location for the toolbar.
            controlY      = controlY + 220;
            toolbar.Frame = new CGRect(controlX, controlY, totalWidth, 30);

            // Add the controls.
            AddSubviews(toolbar, statisticPicker);
        }
        // Constructor that takes a picker for defining new statistics.
        public ChooseStatisticOverlay(UIPickerView statPicker)
        {
            this.TranslatesAutoresizingMaskIntoConstraints = false;
            // Toolbar with "Add" and "Done" buttons.
            UIToolbar toolbar = new UIToolbar();

            toolbar.TranslatesAutoresizingMaskIntoConstraints = false;

            statPicker.TranslatesAutoresizingMaskIntoConstraints = false;

            // Add Button (add the new stat and don't dismiss the UI).
            UIBarButtonItem addButton = new UIBarButtonItem("Add", UIBarButtonItemStyle.Plain, (s, e) =>
            {
                // Get the selected StatisticDefinition.
                StatDefinitionModel statPickerModel   = (StatDefinitionModel)statPicker.Model;
                StatisticDefinition newStatDefinition = statPickerModel.SelectedStatDefinition;
                if (newStatDefinition != null)
                {
                    // Fire the OnMapInfoEntered event and provide the statistic definition.
                    OnStatisticDefined?.Invoke(this, newStatDefinition);
                }
            });

            // Done Button (dismiss the UI, don't use the selected statistic).
            UIBarButtonItem doneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done,
                                                             (s, e) => { OnCanceled?.Invoke(this, null); });

            // Add the buttons to the toolbar.
            toolbar.Items = new[] { addButton, doneButton };

            statPicker.BackgroundColor = UIColor.White;

            // Add the controls.
            AddSubviews(toolbar, statPicker);

            toolbar.BottomAnchor.ConstraintEqualTo(BottomAnchor).Active     = true;
            toolbar.LeadingAnchor.ConstraintEqualTo(LeadingAnchor).Active   = true;
            toolbar.TrailingAnchor.ConstraintEqualTo(TrailingAnchor).Active = true;

            statPicker.TopAnchor.ConstraintEqualTo(TopAnchor).Active            = true;
            statPicker.LeadingAnchor.ConstraintEqualTo(LeadingAnchor).Active    = true;
            statPicker.TrailingAnchor.ConstraintEqualTo(TrailingAnchor).Active  = true;
            statPicker.BottomAnchor.ConstraintEqualTo(toolbar.TopAnchor).Active = true;
        }