Hello,
You could refer to this official documentation Finalizers (C# Programming Guide), and find the following contents:
Finalizers cannot be defined in structs. They are only used with classes.
A class can only have one finalizer.
Finalizers cannot be inherited or overloaded.
Finalizers cannot be called. They are invoked automatically.
A finalizer does not take modifiers or have parameters.
In MAUI, it is more recommended to use BackButtonBehavior
to unsubscribe the MessagingCenter
.
You could refer to the following code:
In EmptyPage.xaml:
<Shell.BackButtonBehavior>
<BackButtonBehavior Command="{Binding TestCommand}"/>
</Shell.BackButtonBehavior>
In your ViewModel.cs:
TestCommand = new Command(Unsubscribe); // the Unsubscribe method is your own method to unsubscribe MessagingCenter
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.