diff --git a/MvvmStuff/RelayCommand.cs b/MvvmStuff/RelayCommand.cs deleted file mode 100644 index 71d5cc4..0000000 --- a/MvvmStuff/RelayCommand.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Windows.Input; - -namespace ModernWpfPlayground.MvvmStuff -{ - public class RelayCommand : ICommand - { - private readonly Predicate? _canExecute; - private readonly Action _execute; - - public RelayCommand(Action execute) - { - _execute = execute; - } - - public RelayCommand(Action execute, Predicate canExecute) - { - _canExecute = canExecute; - _execute = execute; - } - - public event EventHandler CanExecuteChanged - { - add => CommandManager.RequerySuggested += value; - remove => CommandManager.RequerySuggested -= value; - } - - public bool CanExecute(object parameter) => _canExecute?.Invoke(parameter) ?? true; - - public void Execute(object parameter) - { - _execute(parameter); - } - } -} \ No newline at end of file diff --git a/WindowViewModel.cs b/WindowViewModel.cs index dc02849..3f71068 100644 --- a/WindowViewModel.cs +++ b/WindowViewModel.cs @@ -8,6 +8,7 @@ using System.Windows; using System.Windows.Input; using Microsoft.Win32; using ModernWpfPlayground.MvvmStuff; +using Prism.Commands; namespace ModernWpfPlayground { @@ -43,11 +44,11 @@ namespace ModernWpfPlayground public WindowViewModel() { - ShowDialogCommand = new RelayCommand(async x => await ShowDialogAsync().ConfigureAwait(false)); - CloseCommand = new RelayCommand(x => Application.Current.Shutdown()); - OpenViewModelCommand = new RelayCommand(x => LoadViewModel()); - SaveViewModelCommand = new RelayCommand(x => SaveViewModel()); - ResetViewModelCommand = new RelayCommand(x => + ShowDialogCommand = new DelegateCommand(async () => await ShowDialogAsync().ConfigureAwait(false)); + CloseCommand = new DelegateCommand(() => Application.Current.Shutdown()); + OpenViewModelCommand = new DelegateCommand(LoadViewModel); + SaveViewModelCommand = new DelegateCommand(SaveViewModel); + ResetViewModelCommand = new DelegateCommand(() => { ResetViewModel(); Path = null; @@ -91,7 +92,7 @@ namespace ModernWpfPlayground set => SetProperty(value); } - public RelayCommand ShowDialogCommand { get; } + public ICommand ShowDialogCommand { get; } public string WelcomeMessage {