How to programmatically click a button in WPF?

tghoang picture tghoang · Apr 8, 2009 · Viewed 125.6k times · Source

Since there's no button.PerformClick() method in WPF, is there a way to click a WPF button programmatically?

Answer

Denis Vuyka picture Denis Vuyka · Apr 9, 2009

Like JaredPar said you can refer to Josh Smith's article towards Automation. However if you look through comments to his article you will find more elegant way of raising events against WPF controls

someButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));

I personally prefer the one above instead of automation peers.