Skip to content

Commit

Permalink
Merge pull request #3151 from PrismLibrary/dev/ds/bindingcontext-cleared
Browse files Browse the repository at this point in the history
Delay nulling BindingContext on Android
  • Loading branch information
dansiegel authored May 31, 2024
2 parents 2d9cf89 + c114627 commit be3d431
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Maui/Prism.Maui/Common/MvvmHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,20 @@ public static void DestroyPage(IView? view)

InvokeViewAndViewModelAction<IDestructible>(view, v => v.Destroy());

if (view is Page page)
if (view is VisualElement visualElement)
{
page.Behaviors?.Clear();
page.BindingContext = null;
#if ANDROID
visualElement.Unloaded += VisualElementUnloaded;
void VisualElementUnloaded(object? sender, EventArgs e)
{
visualElement.Unloaded -= VisualElementUnloaded;
visualElement.Behaviors?.Clear();
visualElement.BindingContext = null;
}
#else
visualElement.Behaviors?.Clear();
visualElement.BindingContext = null;
#endif
}
}
catch (Exception ex)
Expand All @@ -75,7 +85,7 @@ public static void DestroyPage(IView? view)
}
}

private static void DestroyChildren(IView page)
private static void DestroyChildren(IView? page)
{
switch (page)
{
Expand Down

0 comments on commit be3d431

Please sign in to comment.