Rg.Plugins.Popup is not closing when background is clicked in Xamarin.Forms

守給你的承諾、 提交于 2019-12-24 18:26:24

问题


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.




回答3:


At first, I put all my StackLayout in a ScrollView and I had the same problem. Then I remove the ScrollView and it works.



来源:https://stackoverflow.com/questions/47993556/rg-plugins-popup-is-not-closing-when-background-is-clicked-in-xamarin-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!