Reputation: 20279
I have a button defined in XAML:
<Button x:Name="loginButton" Text="Login" Clicked="OnLoginButtonClicked" />
Is there a possibility to raise the Clicked
event programmatically? Of course I could call OnLoginButtonClicked
, but I'm interested how the Clicked
event itself can be raised.
Upvotes: 4
Views: 4302
Reputation: 91
If you just want to call the Clicked action, you can do this trick:
var b = new Button();
b.Clicked += (x, y) =>
{
//Your method here
};
var t = b as IButtonController;
t.SendClicked(); //This will call the action
It is important to note this is not the right one. As it was mentioned before, calling the actual method is preferred.
Upvotes: 5
Reputation: 248
Assing a delegate method
testButton3.TouchUpInside += HandleTouchUpInside;
Add the method
void HandleTouchUpInside (object sender, EventArgs ea)
{
new UIAlertView("Touch3", "TouchUpInside handled", null, "OK", null).Show();
}
Upvotes: 0
Reputation: 5370
You can call DoSomething by event handler or any other place in your code
void OnLoginButtonClicked(object sender, EventArgs e)
{
DoSomething ();
}
private void DoSomething()
{
//Click code here.
}
Upvotes: 1