Sometimes you need to to trigger a click or some other event for one of your WPF controls, such as a button, a menu or a checkbox directly from code. There are no methods on the controls themselves do do this directly per event type. However it is not a big deal anyway - simply use RaiseEvent like this (assuming you have a MenuItem object called item):
item.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
That's it. The only thing to be careful with is calling RaiseEvent from inside another event handler for the object.
Post new comment