Aracılığıyla paylaş


MVVM Araç Seti hatası MVVMTK0015

hedeflerinin [NotifyPropertyChangedFor] üst türünde (farklı) erişilebilir bir özellik olması gerekir.

Aşağıdaki örnek MVVMTK0015 oluşturur:

using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

public partial class SampleViewModel : ObservableObject
{
    // The containing type has no property named "FooBar"
    [ObservableProperty]
    [NotifyPropertyChangedFor("FooBar")]
    private string name;
}

Özellik adı yalnızca nullise aynı durum geçerlidir:

using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

public partial class SampleViewModel : ObservableObject
{
    // The target property name is invalid (cannot be null)
    [ObservableProperty]
    [NotifyPropertyChangedFor(null)]
    private string name;
}

Ayrıca, hedef üyenin türü de doğrulanır:

using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

public partial class SampleViewModel : ObservableObject
{
    // The target member "Foo" should be a property, but it's a method
    [ObservableProperty]
    [NotifyPropertyChangedFor(nameof(Foo))]
    private string name;

    public void Foo()
    {
    }
}

Ek kaynaklar

  • Birim testlerinde daha fazla örnek bulabilirsiniz.