Click here to Skip to main content
12,747,162 members (31,195 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 5 Mar 2014

WPF: Programmatically click the default button

, 5 Mar 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Invoke Button.Click event and associated ICommand on the current default button.

A one liner:

System.Windows.Input.AccessKeyManager.ProcessKey(null, "\x000D", false); 


A WPF Button with IsDefault set true registers itself with the AccessKeyManager, specifying the carriage return char (0x000d) as access key.

So AccessKeyManager.ProcessKey() will invoke the default button's ButtonBase.OnAccessKey(), which raises Click event and executes any associated command.
No need to loop controls to find the current default button.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170215.1 | Last Updated 5 Mar 2014
Article Copyright 2014 by OrlandoCurioso
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid