Issue with Community MVVM messaging and storage service. #21088
Replies: 6 comments 4 replies
-
|
1 - Receiving class must comply to IRecipient, Example: 2 - Then implement Receive, Example: Edit: Struggling with tags: IRecipient generic of received type |
Beta Was this translation helpful? Give feedback.
-
|
Maybe related to: CommunityToolkit/dotnet#898 |
Beta Was this translation helpful? Give feedback.
-
|
Does not seem to be an Avalonia issue... |
Beta Was this translation helpful? Give feedback.
-
|
I use Community MVVM messaging a lot, and see a problem here. In this snippet: WeakReferenceMessenger.Default.Register<MainWindow, FilePickerRequestMessage>
(this, async (r, m) =>
{
// Use the top-level window's StorageProvider
// Note: If I put a breakpoint here - it hits it after the viewmodel sends the message
var files = await r.StorageProvider.OpenFilePickerAsync(m.Options);
m.Reply(files); // Send the result back to the ViewModel
});Messenger callback should NOT be async. One of ways to fix it is introducing another local function: WeakReferenceMessenger.Default.Register<MainWindow, FilePickerRequestMessage>
(this, static (r, m) => m.Reply(Handle(r, m.Options)));
static async Task<IEnumerable<IStorageFile>> HandleFilePickerRequestMessage(MainWindow w, FilePickerOpenOptions o)
{
return await w.StorageProvider.OpenFilePickerAsync(o);
}(I also used "static" where possible to avoid leaked state/closures). |
Beta Was this translation helpful? Give feedback.
-
|
MaxKatz6 reply fixed it |
Beta Was this translation helpful? Give feedback.
-
|
I created working examples in https://github.com/tomhornyak/TomsAvaloniaExamples. Hopefully it can help others. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The problem is I get an exception "No response was received for the given request message." after sending it in the view model. But I do hit the breakpoint at the storage provider and it's not null, although the dialog is not shown. I am still learning how Avaloina and the community.mvvm works, so any help would be appreciated.
The Message
Register in OnLoaded
The View Model
Beta Was this translation helpful? Give feedback.
All reactions