Skip to content

Allow ObservableObject/INotifyPropertyChanged generator to work with interface specified #1107

@huoyaoyuan

Description

@huoyaoyuan

Currently, using [ObservableObject]/[INotifyPropertyChanged] generator in WinUI project causes warning MVVMTK0049/0050, since WinRT source generator can't see the implemented interface in MVVMTK source generator.

A workaround for this can be explicitly specify the interfaces in user written part, then they are visible to WInRT source generator:

[INotifyPropertyChanged]
public abstract partial class MyControlBase : UserControl, INotifyPropertyChanged
{
}

However, when the MVVMTK generator sees the interface specification, it will think the interface is implemented by user and remove its generation. If we can force it to provide its generation, then the AOT warning should be addressed.


I also find a workaround by introducing another level of inheritance:

[INotifyPropertyChanged]
public abstract partial class ObservableUserControl : UserControl
{
}

public partial class MyControl : ObservableUserControl, INotifyPropertyChanged

Then WinRT source generator will correctly see interfaces on MyControl, only ObservableUserControl is missing the interface info. Is it safe to ignore the warnings for abstract types?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions