我正在研究Josh Smith的CommandSink示例,并且base.Executed += (s, e) =>...结构正在抛弃我,有人可以帮助使这个晶莹剔透吗?
我的理解:
我不明白的是:
这是上下文中的代码:
public class CommandSinkBinding : CommandBinding
{
#region CommandSink [instance property]
ICommandSink _commandSink;
public ICommandSink CommandSink
{
get { return _commandSink; }
set
{
if (value == null)
throw new ArgumentNullException("Cannot set CommandSink to null.");
if (_commandSink != null)
throw new InvalidOperationException("Cannot set CommandSink more than once.");
_commandSink = value;
base.CanExecute += (s, e) =>
{
bool handled;
e.CanExecute = _commandSink.CanExecuteCommand(e.Command, e.Parameter, out handled);
e.Handled = handled;
};
base.Executed += (s, e) =>
{
bool handled;
_commandSink.ExecuteCommand(e.Command, e.Parameter, out handled);
e.Handled = handled;
};
}
}
...
Run Code Online (Sandbox Code Playgroud)
Eoi*_*ell 11
(s, e) 是事件处理程序的方法参数签名(在这种情况下是定义的anoymous方法)
认为 (object Sender, EventArgs e)
该s参数只是没有在方法的其余部分使用,这很好.它必须与预期的签名相匹配
base.CanExecute += (s, e) =>
{
bool handled;
e.CanExecute = _commandSink.CanExecuteCommand(e.Command, e.Parameter, out handled);
e.Handled = handled;
};
Run Code Online (Sandbox Code Playgroud)
相当于做
base.CanExecute += new EventHandler(myMethod_CanExecute);
///....
protected void myMethod_CanExecute(object sender, EventArgs e)
{
bool handled;
e.CanExecute = _commandSink.CanExecuteCommand(e.Command, e.Parameter, out handled);
e.Handled = handled;
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2027 次 |
| 最近记录: |