如何在我的代码中触发按钮单击? [英] how to trigger a button click in my code?
本文介绍了如何在我的代码中触发按钮单击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何直接在我的代码中触发按钮点击?
How can I trigger a button click directly in my code?
我有这样的代码:
namespace App1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// fire a click ebent von the "Button" MyBtn
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// ...
}
}
}
是否可以通过按钮 MyBtn
触发点击事件?如果是,如何?
Is it possible to fire a click event von the button MyBtn
? If yes how?
我知道我可以调用 Button_Click
方法,但我想通过按钮调用它.
I know I can call the Button_Click
method, but I want to call it over the button.
类似:MyBtn.FireClickEvent();
推荐答案
可以从代码中触发Button_Click
事件如下:
You can trigger the Button_Click
event from the code as follows:
MyBtn.PerformClick();
你也可以试试这个:
MyBtn.Click(new object(), new EventArgs());
这篇关于如何在我的代码中触发按钮单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文