Replies: 2 comments
-
|
I would recommend to not use (Dis)Appearing on maui, they're very unreliable. It's best to change that to (Un)load events instead. Sadly we can't changing any of that triggers, since popups are just a modal page doing a modal navigation. So that will trigger those lifecycle events |
Beta Was this translation helpful? Give feedback.
-
|
I would (1) add guard to ensure initialize only happens once and when you want it to, (2) post-process the query attributes to prevent locking to UI from heavy operations: bool _initialized = false;
IDictionary<string, object> _query;
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
if (!_initialized)
{
_initialized = true;
_query = query;
Dispatcher.Dispatch(async () => await PostInitializeAsync());
}
}
async Task PostInitializeAsync()
{
// Separate query attribute processing to prevent blocking the UI thread.
// For non-UI operations, consider offloading to a background thread using await Task.Run(/* ... */).
}If ApplyQueryAttributes is in your view model not on your view, I would recommend passing in the Dispatcher from your View (e.g. ContentPage) to your ViewModel, e.g. // add this to my view model
public IDispatcher? Dispatcher { get; set; }// set it from your view (e.g. ContentPage)
viewModel.Dispatcher = Dispatcher; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, apologies in advance if I'm approaching this problem the wrong way. I'm relatively new to MAUI and shell, having just migrated from Xamarin.Forms and MvvmCross.
Is there a way to disable the lifecycle methods that result from shell navigation when opening and closing a popup? Specifically, OnAppearing, OnDisappearing, and ApplyQueryAttributes? I see the event args in OnNavigatedTo now have an extension method to determine if the previous page was a popup, but what about these other methods?
To provide a little more context, here's an example of why I'm trying to break this pattern:
Similarly, say I attach event handlers on OnAppearing and detach them on OnDisappearing. The original view is still visible behind the popup, even if it's not on top of the navigation stack. I want the parent view that opens the popup to still handle events while the popup is open, but obviously this no longer happens if I'm detaching event handlers in the OnDisappearing lifecycle method.
I see a couple of ways around this, none of which are particularly intuitive:
Anyways, let me know if I'm going about this all wrong, or if this is a relatively common problem with an obvious solution. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions