Click here to Skip to main content
12,244,489 members (49,446 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

5.4K views
4 bookmarked
Posted

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); 

Background

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.

License

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

Share

About the Author

OrlandoCurioso
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

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