Click here to Skip to main content
Click here to Skip to main content

Tagged as

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

Comments and Discussions

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