CommunityToolkit / CommunityToolkit/Maui
[BUG] VisualState not updating properly when closing a popup from Popup V2
- Dominant language
- C#
- Stars
- 2.7k
- Forks
- 500
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 7
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Did you read the "Reporting a bug" section on Contributing file?
- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
### Current Behavior
To simplify, picture a simple popup (with the popup V2 implementation) with a single button in it, used to close the popup.
When running my app on Windows and opening the popup, the popup seem to work just fine. However, when closing the popup, and re-opening it, the button appears to be stuck in the "Pressed" VisualState. Clicking on it then calls the command as expected, but the button doesn't have the correct appearance.
A Gif video showing the issue :

### Expected Behavior
When reopening the popup, the button should be using the "Normal" VisualState instead of "Pressed".
### Steps To Reproduce
1. Open and run the solution from the reproduction repository
2. Open the popup, and close it by clicking on the "Close" button
3. Open the popup again : the button uses the wrong VisualState.
(4. There is actually a trick to "reset" the button : click and hold on the button, then get the mouse pointer out of the clickable zone. Somehow it resets it.)
### Link to public reproduction project repository
https://github.com/gchapeaux/Sandbox_Popup
### Environment
```markdown
- .NET MAUI CommunityToolkit: 12.2.0
- OS: Windows 11 Professionnal
- .NET MAUI: Maui 9.0
```
### Anything else?
I tried an unsuccessful workaround, but still worth sharing : I wanted to manually update the button's VisualState through its OnClicked event. However, with this tentative, the button appears at first in the correct VisualState, but once mouseovered it goes back to the "Pressed" state.
EDIT : a workaround suggested by @bijington : declare the popup as Transient instead of Singleton
Contributor guide
Research direction
Start by running the linked Sandbox_Popup reproduction on Windows with .NET MAUI CommunityToolkit 12.2.0, then trace the Popup V2 lifecycle and VisualState handling when the popup closes and reopens. Compare the reported Singleton behavior with the suggested Transient workaround. Done means the button returns to the Normal VisualState after reopening and behaves correctly on subsequent mouse interaction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100