MVVM Implementing started
This commit is contained in:
50
SewerStammGen/ViewModel/RelayCommand.cs
Normal file
50
SewerStammGen/ViewModel/RelayCommand.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace SewerStammGen.ViewModel
|
||||
{
|
||||
[Serializable]
|
||||
class RelayCommand : ICommand
|
||||
{
|
||||
#region Fields
|
||||
private readonly Action<object> execute;
|
||||
private readonly Predicate<object> canExecute;
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
public RelayCommand(Action<object> execute) : this(execute, null) { }
|
||||
|
||||
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
|
||||
{
|
||||
if (execute == null) throw new ArgumentNullException("execute");
|
||||
this.execute = execute;
|
||||
this.canExecute = canExecute;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ICommand Members
|
||||
[DebuggerStepThrough]
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
if (canExecute == null) return true;
|
||||
return canExecute(parameter);
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add { CommandManager.RequerySuggested += value; }
|
||||
remove { CommandManager.RequerySuggested -= value; }
|
||||
}
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
execute(parameter);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user