Reputation: 147
I want to add an event handler to the "go" button on the UIKeyboard that appears when entering into an EntryElement. Here is my code
EntryElement cPassword;
//
cPassword = new EntryElement (" ", "Password", "", true) {
ReturnKeyType = UIReturnKeyType.Go
};
//
cPassword.ShouldReturn += () => { Login (); };
The Login method return void and performs a basic logging operation with the entry details provided by the user.
private void Login ()
{
// Do login stuff
//
}
But I think it requires a method of return type func as this is the error message I get when trying to use the current code:
Not all code paths return a value in anonymous method of type 'System.Func<bool>'
(CS1643)
This is the first time I've come up against this type of thing, never seen func<> before :/ and hope that someone could point me in the right direction to using it correctly. Thanks!
Upvotes: 1
Views: 406
Reputation: 8170
Your anonymous method should return a bool:
cPassword.ShouldReturn = () => {
Login();
return true;
};
Also note that since ShouldReturn is a property of a delegate type, the best practice is to assign the value, not add to it like you would do with events ("+=").
Upvotes: 2