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
There are a couple of issues with this bug.
The description reflects the execution sequence:
By the time
DisplayActionSheet
is called inOnAppearing
, thePage
knows itIsPlatformEnabled
is false, so it adds this task into a_pendingActions
list.This list will be drained when
IsPlatformEnabled
is set to true duringCreatePlatformWindow
. While theHandler
is available, the underlying WinUI objects are not on the VisualTree yet, so it isn't really ready to run the_pendingActions
.In particular, at that point of time, the page is not null, but its parent is null, so the call will silently terminate without signaling the async result, and the async call would appear to be forever executing. So I changed the code to
SetResult(null)
even in those cases, those case should not happen, but it could if the user calls the API inappropriately.If we give the page instead of its parent to
actionSheet.ShowAt()
, the call would fail with anE_INVALIDARG
returned from the underlying native code, presumably because it is not in the VisualTree as the comment indicates. The exception handler would try to useUI.Xaml.Window.Current.Content
instead, butUI.Xaml.Window.Current
isnull
at that point of time, further confirming it is too early to make this call.I experimented with moving the flushing of the
_pendingActions
to some time later, such asOnSizeAllocated
, this will work. This is not ideal though, as the method is called quite frequently on resizing. I am wondering if there is a better place to flush them. It has to be at a point where the objects are already in the VisualTree.The code is tested on both Windows and Android emulator, at the moment I am not able to test on other platforms. I assumed that
OnLoaded
should function properly on all platforms.Issues Fixed
Fixes #3726