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.