如何使用显式函数重写命令? [英] How do I rewrite a Command using explicit functions?

查看:56
本文介绍了如何使用显式函数重写命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图理解 ICommand 。我做了很多阅读。几乎所有这些都显示使用lambda语法指定 Command 的机制。我可以看到它的价值,但是,为了加深我的理解,我想知道如何使用单独的函数来编写代码。



如果我有这个Command构造函数:



Hi,

I am trying to get my head around ICommand. I've done a lot of reading. Almost all of it shows the mechanics of the Command being specified using lambda syntax. I can see the value of that, but, simply to deepen my understanding, I would like to know how to write the code long-hand, using separate functions.

If I have this Command constructor:

ICommand myCommand = new Command(
async ( o ) =>
{
	await Task.Delay( 3000 );
},
( o ) =>
{
	return true;
} );





如何使用显式函数代替两个lambda表达式重写它?



亲切的愿望~Patrick



How would I rewrite this using explicit functions in place of the two lambda expressions?

Kind wishes ~ Patrick

推荐答案

看似简单:

Seems simple enough:
private bool MyCommandCanExecute(object state)
{
    return true;
}

private void MyCommandExecute(object state)
{
    // Do something...
}

...

ICommand myCommand = new Command(MyCommandExecute, MyCommandCanExecute);


这篇关于如何使用显式函数重写命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆