Error MVVMTK0015 when the desired NotifyPropertyChangedFor property is an explicit interface implementation
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 48/100
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
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:
- There is a public property named
Enabled, it's simply of lessened visibility (only visible through the interface) - 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
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de CommunityToolkit/dotnet
-
bug :bug:
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
CommunityToolkit/dotnet#1206 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
CommunityToolkit/dotnet#648 ·
-
bug :bug:
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
CommunityToolkit/dotnet#1215 ·
-
feature request :mailbox_with_mail:
Dificultad 5/5 Más de una semana Aptitud para principiantes 45/100
CommunityToolkit/dotnet#1214 ·
Todos los issues de CommunityToolkit/dotnet
Issues similares
-
copilot documentation
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 2 días
-
needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
elsa-workflows/elsa-foundation#2290 ·
Los mantenedores suelen responder en 1 día
-
python triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
microsoft/semantic-kernel#14522 ·
Los mantenedores suelen responder en 4 días
-
area-integrations needs-area-label triage:bot-seen triage:needs-human
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
microsoft/aspire#20652 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
agoda-com/Shouldly.FromAssert#40 ·
Los mantenedores suelen responder en 1 día