Touch events on background elements triggered when popup is open in .NET MAUI

KarPreet 80 Reputation points
2025-02-10T10:13:09.31+00:00

I am using a ContentView as a popup in my .NET MAUI app. The popup displays correctly, but when I tap inside the popup (e.g., on the title), touch events from background elements (like a Entry or Button) are still triggered. This causes issues like the keyboard opening when tapping the popup title because there is an Entry behind it.

How can I prevent background elements from receiving touch events when the popup is open?

Any help would be appreciated! Thanks.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,925 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 48,421 Reputation points Microsoft Vendor
    2025-02-11T02:25:51.0333333+00:00

    Hello,

    An easy way to disable touch events on the parent page when a popup is opened is to control the operability of the page through the Popup's lifecycle events.

    You can control the clickability of all elements through the IsEnabled property of the outermost layout of the parent page. The following is a minimized code example:

    xaml:

    <VerticalStackLayout x:Name="layout"
    

    in code-behind:

    var popup = new MyPopup();
    popup.Opened += (s, e) =>
    {
        layout.IsEnabled = false;
    };
    popup.Closed += (s, e) =>
    {
        layout.IsEnabled = true;
    };
     
    this.ShowPopup(popup);
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.