Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Error MVVMTK0015 when the desired NotifyPropertyChangedFor property is an explicit interface implementation

Abierto
#1,114 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
csharp
Área
devtools

Línea de trabajo

Comienza reproduciendo la implementación explícita de interfaz proporcionada con CommunityToolkit.Mvvm 8.4.0 y rastrea la validación de NotifyPropertyChangedFor que produce MVVMTK0015. Confirma el comportamiento para el ejemplo y, a continuación, actualiza la validación para que se acepte una propiedad de interfaz implementada explícitamente, mientras que los destinos no válidos existentes sigan notificando el diagnóstico.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug :bug:
Describe the bug

A compilation error results for a situation that we think should be valid. Specifically:

error MVVMTK0015: The target(s) of [NotifyPropertyChangedFor] must be a (different) accessible property, but "(the notify-for property name)" has no (other) matches in type (my type) (https://aka.ms/mvvmtoolkit/errors/mvvmtk0015)

It appears that the toolkit's conditions for NotifiyPropertyChangedFor are not satisfied when the property exists only as an explicitly-implemented interface property.

Regression

No response

Steps to reproduce

Given this simplified reproduction:

public interface IMenuItem
{
    bool Enabled { get; }
}

public partial class MenuItem : ObservableObject, IMenuItem
{
    [ObservableProperty]
    [NotifyPropertyChangedFor(nameof(IMenuItem.Enabled))]
    public partial int ValueThatAffectsEnabled { get; set; }

    bool IMenuItem.Enabled => ValueThatAffectsEnabled > 0;
}

Compiling results in the following error:

error MVVMTK0015: The target(s) of [NotifyPropertyChangedFor] must be a (different) accessible property, but "Enabled" has no (other) matches in type MenuItem (https://aka.ms/mvvmtoolkit/errors/mvvmtk0015)

Expected behavior

We expect this to be allowed by the NotifyPropertyChangedFor attribute's validation because:

  1. There is a public property named Enabled, it's simply of lessened visibility (only visible through the interface)
  2. It is a very common for our views to work with their View Models as interfaces, not concrete types. This lets us swap in/out compatible view model types.

We can work around this:

  • We could make those properties not explicit interface implementations (we'd rather not, we design member visibility very intentionally).
  • We could add OnXXXXChanged() partial methods to manually call OnPropertyChanged("the desired property").

but it would be better if the library would allow this.

Screenshots

No response

IDE and version

VS 2022

IDE version

17.14.10

Nuget packages
  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)

8.4.0

Additional context

No response

Help us help you

No, just wanted to report this

Lenguaje dominante
C#
Estrellas
3.8k
Forks
401
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de CommunityToolkit/dotnet

Todos los issues de CommunityToolkit/dotnet

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.