コード例 #1
0
        public MainPage()
        {
            //отрисовываем кнопку в коде, дальнейшее рисование элементов на странице будет не достуно
            Title = "Домашняя страница";

            connectionStateLbl = new Label
            {
                Text              = "Подключение отсутствует",
                FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
            };
            connectionDetailsLbl = new Label
            {
                FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
            };

            CrossConnectivity.Current.ConnectivityChanged += CurrentConnectivityChanged;

            //кнопка открытия страницы сканера
            Button toAdminPageBtn = new Button
            {
                Text = "AdminPage",
                //BackgroundColor = Color.Green,
                BackgroundColor   = Color.FromHex("#12B812"),
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                BorderWidth       = 2,
                BorderColor       = Color.White
            };

            //begin test btn
            Button toDBpage = new Button
            {
                Text = "Результаты сканирования",
                //BackgroundColor = Color.Red,
                BackgroundColor   = Color.FromHex("#12B812"),
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                BorderWidth       = 2,
                BorderColor       = Color.White
            };
            Button toScanner = new Button
            {
                Text = "Сканер",
                //BackgroundColor = Color.Aquamarine,
                BackgroundColor   = Color.FromHex("#12B812"),
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                BorderWidth       = 2,
                BorderColor       = Color.White
                                    //WidthRequest = 177,
                                    //HeightRequest = 174
            };
            Button toGoodsList = new Button
            {
                Text = "Загрузить товары",
                //BackgroundColor = Color.YellowGreen,
                BackgroundColor   = Color.FromHex("#12B812"),
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                BorderWidth       = 2,
                BorderColor       = Color.White
            };
            Button changeOrgOrSklad = new Button
            {
                Text = "Смена клиента/склада",
                //BackgroundColor = Color.SaddleBrown,
                BackgroundColor   = Color.FromHex("#12B812"),
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                BorderWidth       = 2,
                BorderColor       = Color.White,
                IsVisible         = false
            };
            Button Login = new Button
            {
                Text              = "Login",
                BackgroundColor   = Color.FromHex("#12B812"),
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                BorderWidth       = 2,
                BorderColor       = Color.White
            };
            //end test btn

            Grid grid = new Grid
            {
                RowDefinitions = //строки
                {
                    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)
                    }
                }
            };

            var user = App.UsersDatabase.GetItems();

            foreach (var data in user)
            {
                if (data.NameOrg != null && data.SkladName != null)
                {
                    changeOrgOrSklad.IsVisible = true;
                }
            }

            //позиции в строках и колонках
            grid.Children.Add(toAdminPageBtn, 0, 0);
            grid.Children.Add(toDBpage, 0, 1);
            grid.Children.Add(changeOrgOrSklad, 0, 2);
            grid.Children.Add(connectionStateLbl, 0, 3);
            grid.Children.Add(connectionDetailsLbl, 0, 3);
            Grid.SetColumnSpan(connectionStateLbl, 2);
            Grid.SetColumnSpan(connectionDetailsLbl, 2);

            grid.Children.Add(toScanner, 1, 0);
            grid.Children.Add(toGoodsList, 1, 1);
            grid.Children.Add(Login, 1, 2);


            //отлавливаем нажатие кнопки сканирования
            toAdminPageBtn.Clicked += ToAdminPage;

            //нажатие кнопки на страницу работы с БД
            toDBpage.Clicked += ToDBpageWork;

            //тестовые кнопки
            toScanner.Clicked        += ToScannerPage;
            toGoodsList.Clicked      += ToGoodsListPage;
            changeOrgOrSklad.Clicked += ToChangeOrgOrSklad;
            Login.Clicked            += ToLoginPage;

            //добавляем элементы на страницу
            //Content = new StackLayout { Children = { toScannerPageBtn } };
            Content = grid;
        }
コード例 #2
0
        Grid mainGrid     = new Grid();  //Grid 也是 View
        public MainPage()
        {
            mainGrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(100, GridUnitType.Absolute)
            });
            mainGrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            mainGrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            mainGrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            mainGrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            mainGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            mainGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            mainGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            mainGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });

            resultLabel.Text     = "Result";
            resultLabel.FontSize = 50;
            mainGrid.Children.Add(resultLabel, 0, 0);
            Grid.SetColumnSpan(resultLabel, mainGrid.ColumnDefinitions.Count);//=4

            for (int i = 1; i <= 9; i++)
            {
                Button numberButton = new Button {
                    Text = $"{i}"
                };
                numberButton.Clicked += NumberButton_Clicked;
                mainGrid.Children.Add(numberButton, (i - 1) % 3, 1 + (i - 1) / 3);
            }

            {
                Button numberButton = new Button {
                    Text = "0"
                };
                numberButton.Clicked += NumberButton_Clicked;
                mainGrid.Children.Add(numberButton, 1, 4);
            }

            {
                Button button = new Button {
                    Text = "="
                };
                button.Clicked += EqualSignClicked;
                mainGrid.Children.Add(button, 0, 4);
            }

            {
                Button button = new Button {
                    Text = "←"
                };
                button.Clicked += DeleteButtonClicked;
                mainGrid.Children.Add(button, 2, 4);
            }

            char[] signs = { '+', '-', '*', '/' };
            for (int i = 0; i < signs.Length; i++)
            {
                Button button = new Button {
                    Text = $"{signs[i]}"
                };
                button.Clicked += NumberButton_Clicked;
                mainGrid.Children.Add(button, 3, 1 + i);
            }

            this.Content = mainGrid;
        }