2025-01-20 14:05:21 -06:00

43 lines
1.1 KiB
C#

using Breath_of_the_Wild_Multiplayer.MVVM.Model;
using System;
using System.Windows.Input;
namespace Breath_of_the_Wild_Multiplayer.Source_files
{
public class RelayCommand : ICommand
{
private Action<object> _execute;
private Func<object, bool> _canExecute;
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value;}
}
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute == null || _canExecute(parameter);
}
public void Execute(object parameter)
{
try
{
_execute(parameter);
}
catch(Exception ex)
{
SharedData.LoadErrorMessage(ex.Message);
}
}
}
}