[ObservableProperty] cannot be used when inheriting from BaseViewModel with INotifyPropertyChanged implemented #336
Replies: 4 comments 1 reply
-
I am hitting this same issue when making custom controls in .NET maui while utilizing the Notably, the |
Beta Was this translation helpful? Give feedback.
-
I am hitting this same issue too. |
Beta Was this translation helpful? Give feedback.
-
i have the same problem but i just use MAUI binding
|
Beta Was this translation helpful? Give feedback.
-
There's an issue tracking this here: #620 |
Beta Was this translation helpful? Give feedback.
-
When trying to utilize the awesome [ObservableProperty] code generator, I have hit a roadblock caused by my ViewModels having a base class from FreshMvvm library - FreshBasePageModel.
This does not compile with a following message:
I cannot inherit from ObservableObject as I already have a base class. If I try to add the [ObservableObject] or [INotifyPropertyChanged] attributes, I get this:
Shouldn't the code generator leverage my base class already implementing INotifyPropertyChanged interface? When looking at the generated code, I kind of have the idea that [ObservableProperty] is calling into some generated OnPropertyChanged method that is added by [INofifyPropertyChanged] code generator.
Wouldn't it be better if instead of calling the OnPropertyChanged method, it was just invoking PropertyChanged event directly (it is doing this anyway, just wrapped in the OnPropertyChanged method). This would then no longer require [INotifyPropertyChanged] attribute being applied to my viewModel class and [ObservableProperty] could be applied even when inheriting from FreshBasePageModel.
The alternative is for the FreshMvvm library (or any other MVVM framework you are using) to apply the [INotifyPropertyChanged] attribute in its base class, but with my proposed approach this is no longer required. Isn't the whole idea of INotifyPropertyChanged to provide this loose coupling?
Beta Was this translation helpful? Give feedback.
All reactions