Add completed solution for chapter 3

This commit is contained in:
Alvin Ashcraft
2023-05-13 12:29:36 -04:00
parent e29c389e86
commit 5ec4e6e6b4
25 changed files with 861 additions and 0 deletions
@@ -0,0 +1,33 @@
using System;
using System.Windows.Input;
namespace MyMediaCollection.ViewModels
{
public class RelayCommand : ICommand
{
private readonly Action action;
private readonly Func<bool> canExecute;
public RelayCommand(Action action)
: this(action, null)
{
}
public RelayCommand(Action action, Func<bool> canExecute)
{
if (action == null)
throw new ArgumentNullException(nameof(action));
this.action = action;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter) => canExecute == null || canExecute();
public void Execute(object parameter) => action();
public event EventHandler CanExecuteChanged;
public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
}