Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

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


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

Kind wishes ~ Patrick
Posted

1 solution

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

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

...

ICommand myCommand = new Command(MyCommandExecute, MyCommandCanExecute);
 
Share this answer
 
Comments
Patrick Skelton 20-Jan-16 10:06am    
Now I see it, you are right - it seems dead simple. The compiler message was throwing me off, I think - something about not being able to cast to an Action<T>.

Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900