Let’s say there is an event captured on a control and you want to simulate a click of a button to fire whatever that button is bound to do, there are a few ways of doing this, one that I’ve used before is using an AutomationPeer:
AutomationPeer button1AP = UIElementAutomationPeer.CreatePeerForElement(button1); (button1AP.GetPattern(PatternInterface.Invoke) as IInvokeProvider).Invoke();
Another option is to use:
button1.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
I fear I just went for the old-fashioned…
Button on-click method calls method X
Other event calls method X
I shall look up your crazy s**t now…
That works in some cases, but not when you have commands bound to the control as I did.
Ah yes, still haven’t figured out why you’d want to use commands instead of on-click type binding.