Error: "Cannot implicitly convert"void" to "Eventhandler"

Asked

Viewed 296 times

0

I was trying to make a button that passed the information of an entry and a Stacklayout and this error appears to me:

    public MainPage()
    {

        InitializeComponent();

        Entry entry = new Entry() { Keyboard = Keyboard.Numeric };

        Button button = new Button();

        StackLayout stack = new StackLayout()
        {
            Children =
            {
                button,
                entry
            }
        };

        button.Clicked += Button_Clicked(stack, entry); //O erro aparece nessa linha
    }
    private async void Button_Clicked(StackLayout stack, Entry entry)
    {
        int qtd_in = Int16.Parse(entry.Text);

        for (int i = 0; i < qtd_in; i++)
        {
            Entry entradas = new Entry();
            stack.Children.Add(entradas);
        }//O código deveria criar novas entradas de acordo com a primeira entry
    }

1 answer

1


The description of your error already says it all, the clicked expects a return Event Handler and your method is of type void, the correct way to call your method would be more or less like this:

button.Clicked += (object sender, EventArgs e) =>
{
 Button_Clicked(stack, entry);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.