You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] PopupService.ShowPopup causes Behavior.OnAttached to execute more than once #1912
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
Open the Issue.PlatformBehaviorPopupService solution and run the application
Notice the Debug 'Output' window and see the 'attached' events
Click the 'Click me!' button
Monitor the Debug 'Output' window and notice that a new 'attached' event logged each time the button is clicked
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.
@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.
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
Activity
bijington commentedon Jun 4, 2024
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.
bengavin commentedon Jun 4, 2024
@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.
bijington commentedon Jun 4, 2024
When is the attached event logged? When you you click the 'Click me' button or the 'close' button?
bengavin commentedon Jun 4, 2024
@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.
bijington commentedon Jun 4, 2024
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
bijington commentedon Jun 4, 2024
I sadly don't have a working Windows environment right now so I can't look into it yet