Ejemplo n.º 1
0
        public InspectionDetailsPage(string inspectionId)
        {
            _inspectionId = inspectionId;

            _viewModel     = new InspectionDetailsViewModel(inspectionId);
            BindingContext = _viewModel;

            var titleEntry = new Entry
            {
                Placeholder             = "Title",
                HorizontalTextAlignment = TextAlignment.Center
            };

            titleEntry.SetBinding(Entry.TextProperty, nameof(_viewModel.TitleText));

            var notesEditor = new Editor
            {
                BackgroundColor = ColorConstants.EditorBackgroundColor
            };

            notesEditor.SetBinding(Editor.TextProperty, nameof(_viewModel.NotesText));

            _viewPhotosButton = new Button
            {
                Text = "Photos"
            };

            this.SetBinding(TitleProperty, nameof(_viewModel.TitleText));
            NavigationPage.SetBackButtonTitle(this, "");

            Padding = new Thickness(20, 10);

            var relativeLayout = new RelativeLayout();

            Func <RelativeLayout, double> getPhotosButtonHeight = (p) => _viewPhotosButton.Measure(p.Width, p.Height).Request.Height;
            Func <RelativeLayout, double> getPhotosButtonWidth  = (p) => _viewPhotosButton.Measure(p.Width, p.Height).Request.Width;

            Func <RelativeLayout, double> getTitleEntryHeight = (p) => titleEntry.Measure(p.Width, p.Height).Request.Height;
            Func <RelativeLayout, double> getTitleEntryWidth  = (p) => titleEntry.Measure(p.Width, p.Height).Request.Width;

            relativeLayout.Children.Add(titleEntry,
                                        Constraint.Constant(0),
                                        Constraint.Constant(0),
                                        Constraint.RelativeToParent(parent => parent.Width));
            relativeLayout.Children.Add(notesEditor,
                                        Constraint.Constant(0),
                                        Constraint.RelativeToView(titleEntry, (parent, view) => view.Height + view.Y + 10),
                                        Constraint.RelativeToParent(parent => parent.Width),
                                        Constraint.RelativeToParent(parent => parent.Height / 2 - getTitleEntryHeight(parent) - getPhotosButtonHeight(parent) - 30));
            relativeLayout.Children.Add(_viewPhotosButton,
                                        Constraint.RelativeToParent(parent => parent.Width / 2 - getPhotosButtonWidth(parent) / 2),
                                        Constraint.RelativeToView(notesEditor, (parent, view) => view.Height + view.Y + 10));

            Content = new ScrollView {
                Content = relativeLayout
            };
        }
Ejemplo n.º 2
0
        public InspectionDetailsPage(int inspectionId)
        {
            _inspectionId = inspectionId;

            _viewModel     = new InspectionDetailsViewModel(inspectionId);
            BindingContext = _viewModel;

            var notesEditor = new Editor
            {
                BackgroundColor = Color.Green
            };

            notesEditor.SetBinding(Editor.TextProperty, nameof(_viewModel.TitleText));

            _viewPhotosButton = new Button
            {
                Text            = "Photos",
                Image           = "MunichREIcon.png",
                BackgroundColor = Color.Pink
            };
            _viewPhotosButton.SetBinding(Button.IsEnabledProperty, nameof(_viewModel.IsPhotosButtonEnabled));

            var relativeLayout = new RelativeLayout();

            Func <RelativeLayout, double> getNotesEditorHeight = (p) => notesEditor.Measure(relativeLayout.Width, relativeLayout.Height).Request.Height;
            Func <RelativeLayout, double> getNotesEditorWidth  = (p) => notesEditor.Measure(relativeLayout.Width, relativeLayout.Height).Request.Width;

            Func <RelativeLayout, double> getViewPhotosButtonHeight = (p) => _viewPhotosButton.Measure(relativeLayout.Width, relativeLayout.Height).Request.Height;
            Func <RelativeLayout, double> getViewPhotosButtonWidth  = (p) => _viewPhotosButton.Measure(relativeLayout.Width, relativeLayout.Height).Request.Width;

            if (Device.Idiom == TargetIdiom.Phone)
            {
                relativeLayout.Children.Add(notesEditor,
                                            Constraint.Constant(0),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.RelativeToParent(parent => parent.Height * 0.4));
            }
            else
            {
                relativeLayout.Children.Add(notesEditor,
                                            Constraint.Constant(0),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.RelativeToParent(parent => parent.Height * 0.2));
            }

            relativeLayout.Children.Add(_viewPhotosButton,
                                        Constraint.RelativeToParent(parent => parent.Width / 2 - getViewPhotosButtonWidth(parent) / 2),
                                        Constraint.RelativeToParent(parent => parent.Height * 0.4 / 2 - getViewPhotosButtonHeight(parent) / 2));

            this.SetBinding(TitleProperty, nameof(_viewModel.TitleText));

            Padding = new Thickness(20, 10);

            Content = relativeLayout;
        }