Skip to content

[BUG] PopupService.ShowPopup causes Behavior.OnAttached to execute more than once #1912

Closed

Description

@bengavin

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

When a behavior is added to the view's Behaviors collection, and the PopupService ShowPopup [or ShowPopupAsync] method is called, the behavior is re-attached even though it was already in the behaviors collection.

Expected Behavior

The behavior is only attached once, even if ShowPopup is called.

Steps To Reproduce

  1. Open the Issue.PlatformBehaviorPopupService solution and run the application
  2. Notice the Debug 'Output' window and see the 'attached' events
  3. Click the 'Click me!' button
  4. Monitor the Debug 'Output' window and notice that a new 'attached' event logged each time the button is clicked

Link to public reproduction project repository

https://github.com/bengavin/maui-issue-repros/tree/main/Issue.PlatformBehaviorPopupService

Environment

- .NET MAUI CommunityToolkit: 9
- OS: Windows
- .NET MAUI: 8.0.40

Anything else?

No response

Activity

  1. bijington commented on Jun 4, 2024

    @bijington
    Contributor

    Just to double check do you see any detached events logged?

    Also you don't want to be registering your PopupViewModel as a singleton and a transient. I'd remove the Singleton registration from your MauiProgram file.

  2. bengavin commented on Jun 4, 2024

    @bengavin
    Author

    @bijington - I've never seen any detached events logged in the reproduction solution, nor when calling the PopupService in our actual app, but they do occur in our actual solution when the page is navigated away from. PopupService must do something that's causing the behaviors to re-attach that's different than a standard dialog box / action sheet / etc.

  3. bijington commented on Jun 4, 2024

    @bijington
    Contributor

    When is the attached event logged? When you you click the 'Click me' button or the 'close' button?

  4. bengavin commented on Jun 4, 2024

    @bengavin
    Author

    @bijington - when 'Click Me' is clicked [or shortly thereafter], it's while the popup is being displayed.

    Thanks for the note on the ViewModel, that was during some DI troubleshooting of the sample and wasn't supposed to be there.

    I've also verified that on both iOS simulator and Android emulator, the behavior does not seem to occur. The repro has been updated accordingly.

  5. bijington commented on Jun 4, 2024

    @bijington
    Contributor

    Thanks that is both interesting and helpful. It sounds like the approach we use to show the Popup on Windows might be triggering some lifecycle event which we don't want

  6. bijington commented on Jun 4, 2024

    @bijington
    Contributor

    I sadly don't have a working Windows environment right now so I can't look into it yet

  7. locked and limited conversation to collaborators on May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/viewsIssue/Discussion/PR that has to do with ViewsbugSomething isn't workingunverified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions