示例#1
0
        private IButton CreateButton(bool okButton)
        {
            //Create the menu entry "Cancel"
            var label = new Label(okButton ? OkText : CancelText, Content, FontSize.Small)
            {
                Horizontal = HorizontalAlignment.Center,
                Vertical   = VerticalAlignment.Center,
                Layer      = 1,
            };

            //check if there is a background image for this button
            var backgrounImage     = okButton ? StyleSheet.MessageBoxOkImageResource : StyleSheet.MessageBoxCancelImageResource;
            var hasBackgroundImage = !string.IsNullOrEmpty(backgrounImage);

            //Create the menu entry for "OK"
            var button = new RelativeLayoutButton()
            {
                HasBackground = !hasBackgroundImage,
                Horizontal    = HorizontalAlignment.Center,
                Vertical      = VerticalAlignment.Top,
                Size          = new Vector2(Resolution.TitleSafeArea.Width * 0.4f - 16, label.Rect.Height * 2f)
            };

            button.AddItem(label);

            if (hasBackgroundImage)
            {
                button.AddItem(new Image(Content.Load <Texture2D>(backgrounImage))
                {
                    Horizontal         = HorizontalAlignment.Center,
                    Vertical           = VerticalAlignment.Center,
                    Size               = button.Rect.Size.ToVector2(),
                    Highlightable      = false,
                    PulsateOnHighlight = false,
                    FillRect           = true,
                    Layer              = 0
                });
            }

            button.LoadContent(this);
            return(button);
        }