Microscopic Traffic Simulator

- Main Page
- Packages
- Classes
- Files

- File List

RelayCommand.cs
Go to the documentation of this file.
1 using System;
2 using System.Diagnostics;
3 using System.Windows.Input;
4
5 namespace Microscopic_Traffic_Simulator
6 {
10 class RelayCommand : ICommand
11 {
15 readonly Action<object> _execute;
16
20 readonly Predicate<object> _canExecute;
21
26 public RelayCommand(Action<object> execute) : this(execute, null) { }
27
33 public RelayCommand(Action<object> execute, Predicate<object> canExecute)
34 {
35 if (execute == null)
36 throw new ArgumentNullException("execute");
37
38 _execute = execute;
39 _canExecute = canExecute;
40 }
41
47 [DebuggerStepThrough]
48 public bool CanExecute(object parameter)
49 {
50 return _canExecute == null ? true : _canExecute(parameter);
51 }
52
56 public event EventHandler CanExecuteChanged
57 {
58 add { CommandManager.RequerySuggested += value; }
59 remove { CommandManager.RequerySuggested -= value; }
60 }
61
66 public virtual void Execute(object parameter)
67 {
68 _execute(parameter);
69 }
70 }
71 }
System
Microscopic_Traffic_Simulator.RelayCommand.RelayCommand
RelayCommand(Action< object > execute)
Creates a new command that can always execute.
Definition: RelayCommand.cs:26
Microscopic_Traffic_Simulator.RelayCommand.RelayCommand
RelayCommand(Action< object > execute, Predicate< object > canExecute)
Creates a new command.
Definition: RelayCommand.cs:33
Microscopic_Traffic_Simulator.RelayCommand
Command class for binding UI commands with view models.
Definition: RelayCommand.cs:10
Microscopic_Traffic_Simulator
Definition: App.xaml.cs:12
Microscopic_Traffic_Simulator.RelayCommand.CanExecuteChanged
EventHandler CanExecuteChanged
For connecting with Command Manager
Definition: RelayCommand.cs:57
Microscopic_Traffic_Simulator.RelayCommand.Execute
virtual void Execute(object parameter)
Execute action
Definition: RelayCommand.cs:66
Microscopic_Traffic_Simulator.RelayCommand.CanExecute
bool CanExecute(object parameter)
Method for getting if command is possible to run.
Definition: RelayCommand.cs:48