I have one button who want to call when my app starting.
private async void OnGetWeatherButtonClicked(object sender, EventArgs e)
{
//code here
}
How to call this button in the constructor to run when the application start?
You can move the code to a method that you can call from the constructor:
async Task Method(object sender, EventArgs e) {
...
}
private async void OnGetWeatherButtonClicked(object sender, EventArgs e)
{
await Method(sender, e);
}
Then
Public MainPage()
{
InitializeComponent();
await Method(sender, e);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.