Axel
Axel

Reputation: 185

RoutedEventHandler on Button.Click function in WPF

i have this code :

button.Click += clickFunction();

private void clickFunction(object sender, RoutedEventArgs e)
{
        // do something
}

I am pretty sure it should work, i've done this few times, it is usually how button.Click works. But this time, i have an error which say that i can't put a void function in a button.Click. It says i should use a RoutedEventHandler.

Am i not supposed to be able to use a void function? What is a RoutedEventHandler?

Thanks

Upvotes: 1

Views: 665

Answers (1)

SteveZ
SteveZ

Reputation: 195

You have to delete the brackets:

button.Click += clickFunction;

Upvotes: 2

Related Questions