Is there an existing issue for this?
Current Behavior
There is a NullReferenceException that is thrown when an attempt to show a popup occurs as a result of an event firing in the background when the MAUI application has no focus.
Expected Behavior
I would assume the pop-up should show up normally.
Or having read a little more on how pop-ups follow the flyout behavior and close when the app loses focus, I would very least
that there are no exceptions thrown and that an internal handling or perhaps an immediate closure of the pop-up takes place.
(maybe the developer can obtain the result just like normally detecting if there was a tap outside to dismiss...etc)
Steps To Reproduce
1- Download the CommunityToolkit.Maui from github
2- Modify the MultiplePopupPage.xaml.cs file to add a timer to the constructor as follows:
public MultiplePopupPage(IDeviceInfo deviceInfo,
PopupSizeConstants popupSizeConstants,
MultiplePopupViewModel multiplePopupViewModel,
CsharpBindingPopupViewModel csharpBindingPopupViewModel)
: base(multiplePopupViewModel)
{
InitializeComponent();
this.popupSizeConstants = popupSizeConstants;
this.csharpBindingPopupViewModel = csharpBindingPopupViewModel;
//Simulate a call back automatically showing a pop up in 5 seconds.
//Try it with the app in focus and while having lost focus.
Timer x = new Timer(
new TimerCallback((s) =>
{
Shell.Current.Dispatcher.Dispatch(() => HandleButtonPopupButtonClicked(new object(), new EventArgs()));
}),
null, 5000, Timeout.Infinite);
}
3- Run CommunityToolkist.Maui.Sample application in DEBUG mode.
4- Navigate to Views->MultiplePopupPage
5- Immediately switch app focus to a Notepad or any other window.
Link to public reproduction project repository
https://github.com/fkahhaleh/MauiToolkit_Bug_Reproduction.git
Environment
- .NET MAUI CommunityToolkit: v 3.0.0
- OS: Windows 11
- .NET MAUI: 7.0.49 (MAUI Graphics and 2DGraphics)
Anything else?
The error is thrown in MauiPopup.Window.cs @ line:109
VirtualView is actually a proper instance up until line 107, where ShowAttachedFlyout(...) executes and as soon as it returns
VirtualView is null at that point!

Is there an existing issue for this?
Current Behavior
There is a NullReferenceException that is thrown when an attempt to show a popup occurs as a result of an event firing in the background when the MAUI application has no focus.
Expected Behavior
I would assume the pop-up should show up normally.
Or having read a little more on how pop-ups follow the flyout behavior and close when the app loses focus, I would very least
that there are no exceptions thrown and that an internal handling or perhaps an immediate closure of the pop-up takes place.
(maybe the developer can obtain the result just like normally detecting if there was a tap outside to dismiss...etc)
Steps To Reproduce
1- Download the CommunityToolkit.Maui from github
2- Modify the MultiplePopupPage.xaml.cs file to add a timer to the constructor as follows:
3- Run CommunityToolkist.Maui.Sample application in DEBUG mode.
4- Navigate to Views->MultiplePopupPage
5- Immediately switch app focus to a Notepad or any other window.
Link to public reproduction project repository
https://github.com/fkahhaleh/MauiToolkit_Bug_Reproduction.git
Environment
Anything else?
The error is thrown in MauiPopup.Window.cs @ line:109

VirtualView is actually a proper instance up until line 107, where ShowAttachedFlyout(...) executes and as soon as it returns
VirtualView is null at that point!