0

In WinForms it was easy to trigger a button click in code, because the System.Windows.Forms.Button class has a public method called PerformClick that you can call directly.

However, in WPF you end up using the System.Windows.Controls.Button class instead, in which I'm not readily seeing any equivalent method. There is a method called OnClick but it's protected and I'm not sure it would actually trigger a click anyway; it seems to be fired in tandem with the click event.

var button = new System.Windows.Controls.Button();
// how would I trigger the click event here, programmatically?
soapergem
  • 9,263
  • 18
  • 96
  • 152
  • Can you not reference the forms assembly and trigger the event like you did before? – CalebB Apr 02 '15 at 15:39
  • 2
    Possible solution: http://stackoverflow.com/a/733974/4699710 – ilian Apr 02 '15 at 15:40
  • @ilian000 - that's perfect. Somehow I missed that one in my initial Google searches. If a mod wants to close this question as a duplicate that's fine by me; this was the answer I was looking for. – soapergem Apr 02 '15 at 15:41

0 Answers0