public TreasureGeneratorPage()
        {
            _SelectionView = new GradientView();
            _WebView       = new UIWebView();
            _EmailButton   = new GradientButton();
            _EmailButton.SetText("Email");
            _EmailButton.SetImage(UIExtensions.GetSmallIcon("mail"), UIControlState.Normal);
            _EmailButton.ImageEdgeInsets = new UIEdgeInsets(0, 0, 0, 15);
            _EmailButton.TouchUpInside  += EmailButtonClicked;

            Add(_SelectionView);
            Add(_WebView);
            Add(_EmailButton);



            _LevelTab = new GradientButton();
            _LevelTab.SetText("Level");
            CMStyles.StyleTab(_LevelTab, true);
            _SelectionView.StyleBasicPanel();
            _SelectionView.Gradient     = new GradientHelper(CMUIColors.SecondaryColorADark);
            _SelectionView.CornerRadius = 0f;
            _LevelTab.TouchUpInside    += LevelTabClicked;

            _ItemsTab = new GradientButton();
            _ItemsTab.SetText("Items");
            CMStyles.StyleTab(_ItemsTab, false);
            _ItemsTab.TouchUpInside += ItemsTabClicked;


            _SelectionView.Add(_LevelTab);
            _SelectionView.Add(_ItemsTab);

            _LevelView = new GradientView();

            _ItemsView = new GradientView();

            foreach (var v in new GradientView[] { _LevelView, _ItemsView })
            {
                v.StyleBasicPanel();
                v.Gradient = new GradientHelper(CMUIColors.SecondaryColorADarker);
            }

            _ItemsView.Hidden = true;

            _SelectionView.Add(_LevelView);
            _SelectionView.Add(_ItemsView);

            _GenerateButton = new GradientButton();
            _GenerateButton.SetText("Generate");
            _GenerateButton.SetSmallIcon("treasure");
            _SelectionView.Add(_GenerateButton);
            _GenerateButton.TouchUpInside += GenerateButtonClicked;


            //create level items
            _LevelButton = new GradientButton();
            _LevelButton.SetText("Level 1");
            _LevelButton.Tag = 1;
            _LevelView.Add(_LevelButton);
            _LevelPopover = new ButtonStringPopover(_LevelButton);
            _LevelPopover.SetButtonText = true;
            _LevelPopover.ItemClicked  += HandleLevelPopoverItemClicked;

            for (int i = 1; i <= 20; i++)
            {
                _LevelPopover.Items.Add(new ButtonStringPopoverItem()
                {
                    Text = "Level " + i, Tag = i
                });
            }

            _CoinButton = new GradientButton();
            _CoinButton.SetText("Normal Coins");
            _LevelView.Add(_CoinButton);
            _CoinPopover = new ButtonStringPopover(_CoinButton);
            AddLevelPopoverItems(_CoinPopover, "Coins");
            _CoinButton.Tag = 1;

            _GoodsButton = new GradientButton();
            _GoodsButton.SetText("Normal Goods");
            _LevelView.Add(_GoodsButton);
            _GoodsPopover = new ButtonStringPopover(_GoodsButton);
            AddLevelPopoverItems(_GoodsPopover, "Goods");
            _GoodsButton.Tag = 1;

            _ItemsButton = new GradientButton();
            _ItemsButton.SetText("Normal Items");
            _ItemsPopover = new ButtonStringPopover(_ItemsButton);
            _LevelView.Add(_ItemsButton);
            _ItemsButton.Tag = 1;
            AddLevelPopoverItems(_ItemsPopover, "Items");

            //create item items
            _CountButton = new GradientButton();
            _CountButton.SetText("1 Item");
            _CountButton.Tag = 1;

            _ItemsView.Add(_CountButton);
            _CountPopover = new ButtonStringPopover(_CountButton);
            for (int i = 1; i < 61; i++)
            {
                string text = i + (i == 1?" Item":" Items");
                _CountPopover.Items.Add(new ButtonStringPopoverItem()
                {
                    Text = text, Tag = i
                });
            }
            _CountPopover.ItemClicked  += HandleLevelPopoverItemClicked;
            _CountPopover.SetButtonText = true;

            _ChartLevelButton = new GradientButton();
            _ChartLevelButton.SetText("Minor");
            _ChartLevelButton.Tag = 0;
            _ItemsView.Add(_ChartLevelButton);
            _ChartLevelPopover = new ButtonStringPopover(_ChartLevelButton);
            _ChartLevelPopover.SetButtonText = true;
            _ChartLevelPopover.ItemClicked  += HandleItemLevelClicked;;
            _ChartLevelPopover.Items.Add(new ButtonStringPopoverItem()
            {
                Text = "Minor", Tag = 0
            });
            _ChartLevelPopover.Items.Add(new ButtonStringPopoverItem()
            {
                Text = "Medium", Tag = 1
            });
            _ChartLevelPopover.Items.Add(new ButtonStringPopoverItem()
            {
                Text = "Major", Tag = 2
            });

            foreach (var t in new TreasureGenerator.RandomItemType [] {
                TreasureGenerator.RandomItemType.MagicalArmor,
                TreasureGenerator.RandomItemType.MagicalWeapon,
                TreasureGenerator.RandomItemType.Potion,
                TreasureGenerator.RandomItemType.Wand,
                TreasureGenerator.RandomItemType.Ring,
                TreasureGenerator.RandomItemType.Rod,
                TreasureGenerator.RandomItemType.Scroll,
                TreasureGenerator.RandomItemType.Staff,
                TreasureGenerator.RandomItemType.MinorWondrous,
            })
            {
                var b = new GradientButton();
                b.SetText(TreasureGenerator.RandomItemString(t));
                b.Tag = (int)t;
                b.MakeCheckButtonStyle(true);
                b.Data           = true;
                b.TouchUpInside += CheckButtonChecked;
                _ItemsView.Add(b);
                _ItemCheckButtons.Add(b);

                if (t == TreasureGenerator.RandomItemType.Rod)
                {
                    _RodButton         = b;
                    _RodButton.Enabled = false;
                }
                else if (t == TreasureGenerator.RandomItemType.Staff)
                {
                    _StaffButton         = b;
                    _StaffButton.Enabled = false;
                }
            }

            _SelectAllButton = new GradientButton();
            _SelectAllButton.SetText("Select All");
            _ItemsView.Add(_SelectAllButton);
            _SelectAllButton.TouchUpInside += SelectButtonClicked;
            _SelectAllButton.Data           = true;

            _UnselectAllButton = new GradientButton();
            _UnselectAllButton.SetText("Unselect All");
            _ItemsView.Add(_UnselectAllButton);
            _UnselectAllButton.TouchUpInside += SelectButtonClicked;
            _UnselectAllButton.Data           = false;
        }