Exemple #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;
        }
Exemple #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);
        }
Exemple #3
0
        private async void PushPopupPage(PopupPage popupPage, View dialogView, Action <IDialogParameters> closeCallback, bool animated = true)
        {
            View mask    = DialogLayout.GetMask(dialogView);
            var  gesture = new TapGestureRecognizer
            {
                NumberOfTapsRequired = 1,
                Command          = new Command <IDialogParameters>(closeCallback),
                CommandParameter = new DialogParameters()
            };

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

                mask = new BoxView
                {
                    Style = overlayStyle
                };
            }

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

            var overlay       = new AbsoluteLayout();
            var relativeWidth = DialogLayout.GetRelativeWidthRequest(dialogView);

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

            var relativeHeight = DialogLayout.GetRelativeHeightRequest(dialogView);

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

            //AbsoluteLayout.SetLayoutFlags(content, AbsoluteLayoutFlags.PositionProportional);
            //AbsoluteLayout.SetLayoutBounds(content, new Rectangle(0f, 0f, popupPage.Width, popupPage.Height));
            AbsoluteLayout.SetLayoutFlags(dialogView, AbsoluteLayoutFlags.PositionProportional);
            var popupBounds = DialogLayout.GetLayoutBounds(dialogView);

            AbsoluteLayout.SetLayoutBounds(dialogView, popupBounds);
            //overlay.Children.Add(content);
            if (DialogLayout.GetUseMask(dialogView) ?? true)
            {
                overlay.Children.Add(mask);
            }
            else
            {
                overlay.GestureRecognizers.Add(gesture);
            }

            overlay.Children.Add(dialogView);
            popupPage.Content = overlay;
            await _popupNavigation.PushAsync(popupPage, animated);
        }
Exemple #4
0
        private async void PushPopupPage(PopupPage popupPage, View dialogView)
        {
            View mask = DialogLayout.GetMask(dialogView);

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

                mask = new BoxView
                {
                    Style = overlayStyle
                };
            }

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

            var overlay       = new AbsoluteLayout();
            var relativeWidth = DialogLayout.GetRelativeWidthRequest(dialogView);

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

            var relativeHeight = DialogLayout.GetRelativeHeightRequest(dialogView);

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

            //AbsoluteLayout.SetLayoutFlags(content, AbsoluteLayoutFlags.PositionProportional);
            //AbsoluteLayout.SetLayoutBounds(content, new Rectangle(0f, 0f, popupPage.Width, popupPage.Height));
            AbsoluteLayout.SetLayoutFlags(dialogView, AbsoluteLayoutFlags.PositionProportional);
            var popupBounds = DialogLayout.GetLayoutBounds(dialogView);

            AbsoluteLayout.SetLayoutBounds(dialogView, popupBounds);
            //overlay.Children.Add(content);
            if (DialogLayout.GetUseMask(dialogView) ?? true)
            {
                overlay.Children.Add(mask);
            }

            overlay.Children.Add(dialogView);
            popupPage.Content = overlay;
            await _popupNavigation.PushAsync(popupPage);
        }