コード例 #1
0
        private Grid GetGrid()
        {
            example = levelType.CreateExample();

            var grid = new Grid
            {
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = new GridLength(2, GridUnitType.Auto)
                    },
                    new RowDefinition {
                        Height = new GridLength(2, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    }
                },
                BackgroundColor = Color.FromRgb(232, 232, 240)
            };

            question = new Label
            {
                Text      = $"{example.Question}",
                TextColor = Color.FromHex("#6b6e72"),
                FontSize  = 34
            };

            answer = new Label
            {
                FontSize  = 34,
                TextColor = Color.FromHex("#6b6e72"),
            };

            score = new Label
            {
                FontSize  = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                TextColor = Color.FromHex("#6b6e72"),
                Text      = "0"
            };

            var scoreStack = new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                VerticalOptions   = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                Children          = { scoreLabel, score },
                Margin            = new Thickness(10)
            };


            var stackLayout = new StackLayout
            {
                Children          = { question, answer },
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Orientation       = StackOrientation.Horizontal
            };

            var stack = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children    = { scoreStack, stackLayout }
            };

            progressBar = new ProgressBar {
                Progress = 0
            };

            var button1 = new Button
            {
                Text            = "1",
                FontSize        = 34,
                BackgroundColor = color,
                Margin          = new Thickness(5, 0, 0, 0)
            };
            var button2 = new Button
            {
                Text            = "2",
                BackgroundColor = color,
                FontSize        = 34
            };

            var button3 = new Button
            {
                Text            = "3",
                FontSize        = 34,
                BackgroundColor = color,
                Margin          = new Thickness(0, 0, 5, 0)
            };
            var button4 = new Button
            {
                Text            = "4",
                FontSize        = 34,
                BackgroundColor = color,
                Margin          = new Thickness(5, 0, 0, 0)
            };
            var button5 = new Button
            {
                Text            = "5",
                BackgroundColor = color,
                FontSize        = 34
            };

            var button6 = new Button
            {
                Text            = "6",
                FontSize        = 34,
                BackgroundColor = color,
                Margin          = new Thickness(0, 0, 5, 0)
            };
            var button7 = new Button
            {
                Text            = "7",
                FontSize        = 34,
                BackgroundColor = color,
                Margin          = new Thickness(5, 0, 0, 0)
            };
            var button8 = new Button
            {
                Text            = "8",
                BackgroundColor = color,
                FontSize        = 34
            };

            var button9 = new Button
            {
                Text            = "9",
                FontSize        = 34,
                BackgroundColor = color,
                Margin          = new Thickness(0, 0, 5, 0)
            };

            var button0 = new Button
            {
                Text            = "0",
                FontSize        = 34,
                BackgroundColor = color,
                Margin          = new Thickness(5, 0, 0, 5)
            };

            var buttonClear = new Button
            {
                Text            = "←",
                FontSize        = 44,
                BackgroundColor = color,
                Margin          = new Thickness(0, 0, 5, 5)
            };

            button1.Clicked     += AnswerClicked;
            button2.Clicked     += AnswerClicked;
            button3.Clicked     += AnswerClicked;
            button4.Clicked     += AnswerClicked;
            button5.Clicked     += AnswerClicked;
            button6.Clicked     += AnswerClicked;
            button7.Clicked     += AnswerClicked;
            button8.Clicked     += AnswerClicked;
            button9.Clicked     += AnswerClicked;
            button0.Clicked     += AnswerClicked;
            buttonClear.Clicked += ButtonClearOnClicked;

            grid.Children.Add(stack, 0, 1);
            Grid.SetColumnSpan(stack, 3);
            grid.Children.Add(progressBar, 0, 2);
            Grid.SetColumnSpan(progressBar, 3);

            grid.Children.Add(button7, 0, 3);
            grid.Children.Add(button8, 1, 3);
            grid.Children.Add(button9, 2, 3);

            grid.Children.Add(button4, 0, 4);
            grid.Children.Add(button5, 1, 4);
            grid.Children.Add(button6, 2, 4);

            grid.Children.Add(button1, 0, 5);
            grid.Children.Add(button2, 1, 5);
            grid.Children.Add(button3, 2, 5);

            grid.Children.Add(button0, 0, 6);
            grid.Children.Add(buttonClear, 1, 6);
            Grid.SetColumnSpan(buttonClear, 2);

            return(grid);
        }