Skip to content

Commit e0df83b

Browse files
Fix: MAUI Floor Filter Crash on Site Selection in .NET 9 (#645)
* Remove missing AOT compilation from project configuration * Updated navigation methods to use PushAsync and PopAsync instead of PushModalAsync and PopModalAsync, shifting from modal to standard navigation. This is temporary fix that prevents a MAUI bug reported here dotnet/maui#29512 * Fixing indentation * Fixing indentation * Add platform-specific navigation handling * Adding comments to explain the bug and workaround * Adding more detailed comments
1 parent e4ec624 commit e0df83b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Toolkit/Toolkit.Maui/FloorFilter/FloorFilter.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,16 @@ internal async void NavigateForward(ContentPage page)
146146
{
147147
try
148148
{
149+
// See: https://github.com/dotnet/maui/issues/29512
150+
// Explanation: Due to a bug in .NET MAUI 9, navigating from a CollectionView selection using PushAsync avoids a crash that occurs when using PushModalAsync.
151+
// The crash is caused by the CollectionView's VirtualView not being null during navigation, leading to an unhandled exception.
152+
// This workaround uses PushAsync on Windows/Android platforms to prevent the crash. When the bug is fixed in MAUI, this conditional can be revisited.
153+
// TODO: Remove this conditional when the MAUI bug is fixed.
154+
#if WINDOWS && ANDROID
155+
await Navigation.PushAsync(page);
156+
#else
149157
await Navigation.PushModalAsync(page);
158+
#endif
150159
_navigationStackCounter++;
151160
}
152161
catch (Exception ex)
@@ -161,7 +170,14 @@ internal async void CloseBrowsing()
161170
{
162171
try
163172
{
173+
// Workaround for .NET MAUI issue: https://github.com/dotnet/maui/issues/29512
174+
// Use PushAsync on Windows/Android platforms to avoid the crash.
175+
// TODO: Remove this conditional when the MAUI bug is fixed.
176+
#if WINDOWS && ANDROID
177+
await Navigation.PopAsync();
178+
#else
164179
await Navigation.PopModalAsync();
180+
#endif
165181
}
166182
catch (Exception ex)
167183
{
@@ -178,7 +194,14 @@ internal async void GoBack()
178194
{
179195
try
180196
{
197+
// Workaround for .NET MAUI issue: https://github.com/dotnet/maui/issues/29512
198+
// Use PushAsync on Windows/Android platforms to avoid the crash.
199+
// TODO: Remove this conditional when the MAUI bug is fixed.
200+
#if WINDOWS && ANDROID
201+
await Navigation.PopAsync();
202+
#else
181203
await Navigation.PopModalAsync();
204+
#endif
182205
}
183206
catch (Exception ex)
184207
{

0 commit comments

Comments
 (0)