How to raise a click event manually for a button in windows phone ? Is it possible technically ? And is that a good suggestion to raise such event manually ?
Asked
Active
Viewed 1,470 times
1 Answers
0
You can raise events manually just like with any other function, since per-se, an event handler is nothing but a function that is associated with data passed to it in case of an event.
So, let's say you have a mock event handler:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Debug.WriteLine("TEST");
}
You can easily invoke it manually with:
Button_Click_1(btnTest, new RoutedEventArgs());
In this case, you can supply your own sender. If you want to raise an event specifically, without having to explicitly bind to your own event handler, take a look at this answer - you can use Reflection, although I am not sure why you'd need it like that.
-
There's a difference between event and event handler, isn't it? Especially between routed event and event handler. – Haspemulator Feb 15 '13 at 22:47
-
Event != event handler. You raise an event and handle it through an, obviously, event handler. – Den Feb 15 '13 at 23:04
-
OP asked how to raise an event, not how to call a handler function. There is a huge difference between calling one single handler and invoking an event with potentially bug number of listeners. Especially in case of routed events like Click. – Haspemulator Feb 15 '13 at 23:12