CommunityToolkit / CommunityToolkit/MVVM-Samples

Load Async data in a UserControl with SetPropertyAndNotifyOnCompletion instead of NotifyTaskCompletion

Open
#83 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
1.4k
Forks
265
PR merge metrics
No merged PRs in 30d

Description

Hello,

I'm currently modifying a UserControl to remove NotifyTaskCompletion class and use directly the Task with SetPropertyAndNotifyOnCompletion .

I am working on a .NET 4.8 project in WPF and I have the following problem:
Constructor
```
public ArticleCategoryUserControlModel()
{
_serviceProvider = ApplicationBootstrapper.ServiceProvider;

AllArticleCategoriesTask = RequestValuesAsync();
}
```
```
private async Task> RequestValuesAsync()
{
using var scope = _serviceProvider.CreateScope();
var articleCategoryReader = scope.ServiceProvider.GetRequiredService();
await Task.Delay(3000); // for debug purpose
var res = await articleCategoryReader.GetAllAsync();
return new ObservableCollection(res);
}
```

Currently I am still using the following result wrapper:

```
public ObservableCollection AllArticleCategoriesResult =>
AllArticleCategoriesTask.Status == TaskStatus.RanToCompletion
? AllArticleCategoriesTask.Result
: null;
```

Corresponding Xaml

```





```

My question is the following: Is it possible to do the same behavior without the AllArticleCategoriesResult property?

In the Xaml, I can't directly use AllArticleCategories.Result because it causes me to freeze the UI. I have to use the AllArticleCategoriesResult property.

Thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.