次の方法で共有


MVVM Toolkit エラー MVVMTK0006

ObservableValidator から継承されない型で宣言されている場合、検証属性を持つフィールドに [ObservableProperty] を適用できません。

次の例では MVVMTK0006 が発生します:

using System.ComponentModel.DataAnnotations;
using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

[INotifyPropertyChanged]
public partial class SampleViewModel
{
    // The field has a validation attribute (the [Required] attribute), but the
    // containing type (SampleViewModel) doesn't inherit from ObservableValidator
    [ObservableProperty]
    [Required]
    private string name;
}

その他のリソース

  • 単体テスト」では、さらに他の例を見つけることができます。