Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVVM Community Toolkit - Messaging in Maui #377

Open
jwy2020 opened this issue Feb 24, 2024 · 1 comment
Open

MVVM Community Toolkit - Messaging in Maui #377

jwy2020 opened this issue Feb 24, 2024 · 1 comment

Comments

@jwy2020
Copy link

jwy2020 commented Feb 24, 2024

Type of issue

Other (describe below)

Description

I am using the messenger from the toolkit. Specifically, I am sending a message to a page from the main page. If I do not navigate to the second form before sending, the message does not get delivered to the second form. If I do navigate there and back, the messages work as expected. This seems to make sense that the registration to the message has not occurred yet.

Is there any way to send the message and then navigate to the form?

Page URL

https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/messenger

Content source URL

https://github.com/MicrosoftDocs/CommunityToolkit/blob/main/docs/mvvm/Messenger.md

Document Version Independent Id

6f38cc35-64a9-f509-76b6-03469b43cd8b

Article author

@Sergio0694

Metadata

  • ID: 6f38cc35-64a9-f509-76b6-03469b43cd8b
  • Service: dotnet-communitytoolkit
  • Sub-service: mvvm-toolkit
@bijington
Copy link
Collaborator

You can't send a message to something that doesn't exist yet. If you haven't navigated to your page then there won't be one in memory to receive your message. If you need to pass data between pages I would advocate for using something like this: https://learn.microsoft.com/dotnet/maui/fundamentals/shell/navigation?view=net-maui-8.0#pass-data

As an additional point, how are you registering your pages/view models? Transient/singleton/scoped? As you may be getting unexpected behavior if your page receives the message after you navigate away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants