次の方法で共有


MVVM Toolkit エラー MVVMTK0013

キャンセル トークンを受け取る非同期コマンド型にマッピングされていないメソッドにキャンセル コマンドを含める [RelayCommand] 属性を適用できません。

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

using CommunityToolkit.Mvvm.Input;

namespace MyApp;

public partial class SampleViewModel
{
    // The target method is synchronous, so no cancel command can be generated
    [RelayCommand(IncludeCancelCommand = true)]
    private void GreetUser(User user)
    {
    }
}

入力トークンを受け取らない非同期メソッドにも同じことが当てはまります:

using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Input;

namespace MyApp;

public partial class SampleViewModel
{
    // The target method is asynchronous but cannot be cancelled
    [RelayCommand(IncludeCancelCommand = true)]
    private async Task DoWorkAsync()
    {
    }
}

その他のリソース

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