0

Is this redundant?

[ObservableProperty]
ObservableCollection<Country> countries;

I feel like the [ObservableProperty] is not needed since ObservableCollection<> can notify the UI already on its own. Or, an alternative would be:

[ObservableProperty]
List<Country> countries;

Can someone please shed some light on this? The docs from Microsoft confuses me, sorry.

  • Looking at the docs (https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/generators/observableproperty) indicates that this attribute effectively implements `INotifyPropertyChanged` for you (assuming the fields are in a partial class with the necessary infrastructure). That means it's auto generating some code for you to ensure that the UI is notified if the property is set to a different value (i.e. `countries = newData`). You are correct that an `ObservableCollection` would notify the UI if its contents changes, but it wouldn't otherwise update the UI if set to something else. – Rob Kite Mar 16 '23 at 15:49

0 Answers0