CommunityToolkit / CommunityToolkit/dotnet

Refreshing all properties of an ObservableObject

Open
#1,160 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

This issue falls in between a feature request and a bug.

Given a case scenario you want to refresh all the properties of an ObservableObject, the recommended pattern is this:

```c#
public void RefreshAllProperties() => OnPropertyChanged(null);
```

Raising a property changed as null is usually the suggested approach to signal that all properties are changed.

The problem with this pattern is that it assumes the receiving end is able to list (via reflection) all the properties that are bound for refreshment.

But when you're in an AOT scenario, I am wondering if, in this crippled scenario where reflection is not possible, how to resolve this.

I think the solution for this would be, if AOT is detected, instead of raising a single `null` property change, to raise a sequence of indivisual property changes, one for every observable property.

And, I think this can be done in two ways:

1- to have a protected method that enumerates all the observable properties (something that could be usefull for other scenarios, like populating PropertyGrid controls) , and the let the developer implement its own RefreshAllProperties();

2- to make `OnPropertyChanged();` smarter, by detecting when a null argument is passed, and if it detectes its in AOT, instead of relaying the null, to swich to raise a propertychange sequence.

Btw, I'm relatively new to CommunityToolkit.mvvm , so I wrote this issue under the assumption there's no way to do this other to manually raise all the property changes.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.