Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#1,114 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
devtools

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện triển khai giao diện tường minh được cung cấp với CommunityToolkit.Mvvm 8.4.0 và theo dõi quá trình xác thực NotifyPropertyChangedFor tạo ra MVVMTK0015. Xác nhận hành vi của mẫu, sau đó cập nhật quá trình xác thực để một thuộc tính giao diện được triển khai tường minh được chấp nhận, trong khi các đích không hợp lệ hiện có vẫn tiếp tục báo chẩn đoán.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
C#
Star
3.8k
Fork
401
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CommunityToolkit/dotnet

Tất cả issue của CommunityToolkit/dotnet

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.