-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFunctionRunnerCommand.cs
More file actions
37 lines (32 loc) · 924 Bytes
/
FunctionRunnerCommand.cs
File metadata and controls
37 lines (32 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Windows.Input;
namespace FancyGrid
{
/// <summary>
/// A hack to let you use functions or anonymous methods as commands.
/// </summary>
public class FunctionRunnerCommand : ICommand
{
/// <summary>
/// Convert the code to a command
/// </summary>
/// <param name="function">A method, function, or lambda to be treated as a command.</param>
public FunctionRunnerCommand(Action<object> function)
{
_function = function;
}
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
_function(parameter);
}
private Action<object> _function;
}
}