Detect a touch outside of a custom pop up inside ContentView

SiddySiddy Member ✭✭

I want to implement closing of a custom pop up view which is inside my content view. I followed e.g. given in the following link for implementing a custom pop up

Following is my code snippet.

<AbsoluteLayout Padding="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <StackLayout AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All">                

                <ListView x:Name="listview"
                            <TextCell Text="{Binding FirstName}"
                              Detail="{Binding CreatedDate}" />


                <ContentView x:Name="popupListView" BackgroundColor="#C0808080" Padding="10, 0" IsVisible="False" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All"
                    <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
                    <StackLayout Orientation="Vertical" HeightRequest="200" WidthRequest="300" BackgroundColor="White">
                            <ListView x:Name="sampleList" ItemTapped="sampleList_ItemTapped">
                        <Button x:Name="btnDismiss" Text="Dismiss" Clicked="btnDismiss_Clicked" Margin="10" />

I have put a button to dismiss the pop up, but want to implement close if user click outside of content view as well. I have done some looking online for the same, but most implement popupwindow, or check for region on tap.

Any help or suggestions to achieve the required functionality.

Thanks In Advance.



  • ColeXColeX Member, Xamarin Team Xamurai

    You'll need to add TapGestureRecognizer inside ContentView and bind Button Click event to it .

     <ContentView x:Name="popupListView" 
                     Padding="10, 0"
                     AbsoluteLayout.LayoutBounds="0, 0, 1, 1" 
                <TapGestureRecognizer Tapped="btnDismiss_Clicked"/>
Sign In or Register to comment.