Beispiel #1
0
        private void InsertPopupViewInCurrentPage(ContentPage currentPage, View popupView, bool hideOnBackgroundTapped, Action <IDialogParameters> callback)
        {
            View mask = DialogLayout.GetMask(popupView);

            if (mask is null)
            {
                Style overlayStyle = GetOverlayStyle(popupView);

                mask = new BoxView
                {
                    Style = overlayStyle
                };
            }

            mask.SetBinding(VisualElement.WidthRequestProperty, new Binding {
                Path = "Width", Source = currentPage
            });
            mask.SetBinding(VisualElement.HeightRequestProperty, new Binding {
                Path = "Height", Source = currentPage
            });

            if (hideOnBackgroundTapped)
            {
                var dismissCommand = new Command(() => callback(new DialogParameters()));
                mask.GestureRecognizers.Add(new TapGestureRecognizer
                {
                    Command = dismissCommand
                });
            }

            var overlay = new AbsoluteLayout();

            overlay.SetValue(IsPopupHostProperty, true);
            var existingContent = currentPage.Content;
            var content         = new DialogContainer
            {
                Padding           = currentPage.Padding,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                IsPageContent     = true
            };

            currentPage.Padding = new Thickness(0);

            var popupContainer = new DialogContainer
            {
                IsPopupContent    = true,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Content           = popupView,
            };

            var relativeWidth = DialogLayout.GetRelativeWidthRequest(popupView);

            if (relativeWidth != null)
            {
                popupContainer.SetBinding(DialogContainer.WidthRequestProperty,
                                          new Binding("Width",
                                                      BindingMode.OneWay,
                                                      new RelativeContentSizeConverter {
                    RelativeSize = relativeWidth.Value
                },
                                                      source: currentPage));
            }

            var relativeHeight = DialogLayout.GetRelativeHeightRequest(popupView);

            if (relativeHeight != null)
            {
                popupContainer.SetBinding(DialogContainer.HeightRequestProperty,
                                          new Binding("Height",
                                                      BindingMode.OneWay,
                                                      new RelativeContentSizeConverter {
                    RelativeSize = relativeHeight.Value
                },
                                                      source: currentPage));
            }

            AbsoluteLayout.SetLayoutFlags(content, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(content, new Rectangle(0f, 0f, currentPage.Width, currentPage.Height));
            AbsoluteLayout.SetLayoutFlags(popupContainer, AbsoluteLayoutFlags.PositionProportional);
            var popupBounds = DialogLayout.GetLayoutBounds(popupView);

            AbsoluteLayout.SetLayoutBounds(popupContainer, popupBounds);
            overlay.Children.Add(content);

            if (DialogLayout.GetUseMask(popupContainer.Content) ?? true)
            {
                overlay.Children.Add(mask);
            }

            overlay.Children.Add(popupContainer);
            currentPage.Content = overlay;

            // The original content needs to be reparented after the Page Content has been reset.
            content.Content = existingContent;
        }
Beispiel #2
0
        private void InsertPopupViewInCurrentPage(ContentPage currentPage, DialogPage modalPage, View popupView, bool hideOnBackgroundTapped, Action <IDialogParameters> callback)
        {
            View mask = DialogLayout.GetMask(popupView);

            if (mask is null)
            {
                Style overlayStyle = GetOverlayStyle(popupView);

                mask = new BoxView
                {
                    Style = overlayStyle
                };
            }

            mask.SetBinding(VisualElement.WidthRequestProperty, new Binding {
                Path = "Width", Source = modalPage
            });
            mask.SetBinding(VisualElement.HeightRequestProperty, new Binding {
                Path = "Height", Source = modalPage
            });

            if (hideOnBackgroundTapped)
            {
                var dismissCommand = new Command(() => callback(new DialogParameters()));
                mask.GestureRecognizers.Add(new TapGestureRecognizer
                {
                    Command = dismissCommand
                });
            }

            var overlay        = new AbsoluteLayout();
            var popupContainer = new DialogContainer
            {
                IsPopupContent    = true,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Content           = popupView,
            };

            var relativeWidth = DialogLayout.GetRelativeWidthRequest(popupView);

            if (relativeWidth != null)
            {
                popupContainer.SetBinding(DialogContainer.WidthRequestProperty,
                                          new Binding("Width",
                                                      BindingMode.OneWay,
                                                      new RelativeContentSizeConverter {
                    RelativeSize = relativeWidth.Value
                },
                                                      source: modalPage));
            }

            var relativeHeight = DialogLayout.GetRelativeHeightRequest(popupView);

            if (relativeHeight != null)
            {
                popupContainer.SetBinding(DialogContainer.HeightRequestProperty,
                                          new Binding("Height",
                                                      BindingMode.OneWay,
                                                      new RelativeContentSizeConverter {
                    RelativeSize = relativeHeight.Value
                },
                                                      source: modalPage));
            }

            AbsoluteLayout.SetLayoutFlags(popupContainer, AbsoluteLayoutFlags.PositionProportional);
            var popupBounds = DialogLayout.GetLayoutBounds(popupView);

            AbsoluteLayout.SetLayoutBounds(popupContainer, popupBounds);

            if (DialogLayout.GetUseMask(popupContainer.Content) ?? true)
            {
                overlay.Children.Add(mask);
            }

            overlay.Children.Add(popupContainer);

            modalPage.Content    = overlay;
            modalPage.DialogView = popupView;
            currentPage.Navigation.PushModalAsync(modalPage, true);
        }