Rg.Plugins.Popup is not closing when background is

2019-08-17 01:11发布

问题:

I have used rg.plugins.popup in my application. I have updated the xamarin forms (version="2.5.0.121934"). Now the outer background is clicked it is not closed. I used to close the popup many ways, but not closed, I tried the below code:

this.CloseWhenBackgroundIsClicked = false;

protected override bool OnBackgroundClicked()
        {
            Navigation.PopPopupAsync();
            return false;
        }   

OnBackgroundClicked is not calling. How to fix this issue?

回答1:

I don't understand if you know that the correct code is: this.CloseWhenBackgroundIsClicked = true; (not false), but if this is not working you could try a workaround until this problem is solved.

Basically, add a Grid as the root of your PopupPage and add a Colorless BoxView with a TapGestureRecognizer as a child of the Grid, then just add the actual content as another child of the Grid and set the Tapped of the TapGestureRecognizer to the "BackgroundClicked" code.

Hope it helps!



回答2:

I had the same problem, in my case it was about not understanding how this plugin works. First time I used the popup I placed a StackLayout on the center of the screen with this.CloseWhenBackgroundIsClicked = true and it worked pretty well, the problem was when I placed a GridLayout with columns 10*, 80*, 10* and rows 10*, 80*, 10*. my content was going in grid.rows(1), grid.columns(1). the other lines and columns were just borders. If I clicked the borders it would'nt work because I was touching the grid sides and not the actually background. The solution was change Grid for stacklayout and center it.