简体   繁体   中英

How to call a button in the constructor in MainPage when app starting using Xamarin iOS c#

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM