Maui: [BUG] WinUI statecontainer crashes app
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
If you click too fast on the statecontainer change state button in sample, the app crashes due to task cancellation beeing thrown to cancel the state changing task
Expected Behavior
It should just cancel the state change task. Without an exception
Steps To Reproduce
Open windows Navigate to statecontainer Click any state changing button fast enough that a new state is requested before the current state is finished with transitioning.
App hard crash happens in windows, due to WinUI missing a global unhandled exception for async tasks (they have for voids though)
Link to public reproduction project repository
Use the sample app in this repo
Environment
- .NET MAUI CommunityToolkit:
- OS:
- .NET MAUI:
All environments and version of Maui which creates a WinUI application
Anything else?
I can fix this
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17
I’m still looking into the best way to resolve this Issue, but wanted to share a workaround for anyone experiencing this problem in the meantime:
Workaround
Set
ShouldAnimateOnStateChange
tofalse
:XAML
C#
Explanation
The
TaskCanceledException
is thrown whenCurrentState
changes before the fade animation has completed.When
ShouldAnimateOnStateChange == false
, theSwitchToState()
andSwitchToContent()
methods run synchronously (eg They don’t need toawait
the fade animations). This means the methods always complete immediately and never throw aTaskCanceledException
.