Search code examples
buttonuwpclick

PerformClick analogue for UWP


I am writing a helper for Gamepad, so I need to call all click handlers that may be assigned to a button (if any) under focus.

Something like that:

(FocusManager.GetFocusedElement() as ButtonBase)?.PerformClick();

Method PerformClick is supported by WinForms, but I can't find an analogue for UWP. Is there any? Or maybe there is a way to get a set of Click event handlers assigned to a ButtonBase and Invoke them?


Solution

  • You can perform the Click like this -

    var ap = new ButtonAutomationPeer(YourButtonReference);
    var ip = ap.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
    ip?.Invoke();