Fix display of ActionSheet in modal view on Windows #21295
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
When we call
DisplayActionSheetfrom a modal dialog, we encounter an issue with theMauiContextat the following line:maui/src/Controls/src/Core/Platform/AlertManager/AlertManager.Windows.cs
Line 212 in d03a2c6
In this situation,
VirtualView.RequireMauiContext()will return theMauiContextfor theWindow. This is problematic as it causes some strange behavior when converting the view to aHandler. Here, we can see that the view'sHandlerwill be different from theWindow'sHandler`.maui/src/Core/src/Platform/ElementExtensions.cs
Lines 67 to 68 in d03a2c6
As a result, we end up getting a new
Handlerfrom theWindowsMauiContextand setting it here:maui/src/Core/src/Platform/ElementExtensions.cs
Line 96 in d03a2c6
When we set the new

Handler, the modal dialog actually ends up disappearing, while the window itself is still in a modal state, rendering it unusable:Furthermore, we end up getting a null
pageParentwhich leads us to attempt showing theActionSheetfrom thecurrentview:maui/src/Controls/src/Core/Platform/AlertManager/AlertManager.Windows.cs
Lines 219 to 220 in d03a2c6
However, when we execute this here we end up hitting an exception related to a null

XamlRoot:To make matters worse, when we catch the exception we attempt to use
UI.Xaml.Window.Currentto show theActionSheetwhich is also null.maui/src/Controls/src/Core/Platform/AlertManager/AlertManager.Windows.cs
Lines 227 to 228 in d03a2c6
We can avoid this whole debacle by using
sender.RequireMauiContext()instead.Demo
Issues Fixed
Fixes #14829