我在XAML中定义了一个按钮:
<Button x:Name="loginButton" Text="Login" Clicked="OnLoginButtonClicked" />
是否有可能以编程方式提升Clicked
事件?当然我可以打电话给OnLoginButtonClicked
,但我对如何提出Clicked
事件感兴趣。
答案 0 :(得分:3)
如果你只是想调用Clicked动作,你可以这样做:
var b = new Button();
b.Clicked += (x, y) =>
{
//Your method here
};
var t = b as IButtonController;
t.SendClicked(); //This will call the action
重要的是要注意这不是正确的。 如前所述,调用实际方法是首选。
答案 1 :(得分:1)
您可以通过事件处理程序或代码中的任何其他位置调用DoSomething
void OnLoginButtonClicked(object sender, EventArgs e)
{
DoSomething ();
}
private void DoSomething()
{
//Click code here.
}
答案 2 :(得分:0)
分配委托方法
testButton3.TouchUpInside += HandleTouchUpInside;
添加方法
void HandleTouchUpInside (object sender, EventArgs ea)
{
new UIAlertView("Touch3", "TouchUpInside handled", null, "OK", null).Show();
}