ReactivePropertyで2度押し防止
Rxのお勉強。もっと良い実装あったら教えてください。
public class MainVM { public readonly ObservableCollection<string> Messages = new ObservableCollection<string>(); public MainVM() { IsBusy = new ReactiveProperty<bool>(false); Input = new ReactiveProperty<string>(""); TestCommand = IsBusy.CombineLatest(Input, (busy, input) => !busy && !string.IsNullOrEmpty(input)).ToReactiveCommand(); TestCommand.Subscribe(async o => await Test()); } public ReactiveProperty<string> Input { get; } public ReactiveProperty<bool> IsBusy { get; } public ReactiveCommand TestCommand { get; } private async Task Test() { IsBusy.Value = true; await Task.Delay(TimeSpan.FromSeconds(3)); Messages.Add(Input.Value); Input.Value = ""; IsBusy.Value = false; } }