public async Task MoveKeyboardFocus() { var request = new KeyboardFocusRequest { ElementId = Id }; if (await Client.MoveKeyboardFocusAsync(request) is { } reply) { if (reply.ErrorMessages.Any()) { throw new Exception(string.Join(Environment.NewLine, reply.ErrorMessages)); } return; } throw new Exception("Failed to receive a reply"); }
public override async Task <KeyboardFocusResult> MoveKeyboardFocus(KeyboardFocusRequest request, ServerCallContext context) { KeyboardFocusResult reply = new(); await Application.Dispatcher.InvokeAsync(() => { if (!(GetCachedElement <DependencyObject>(request.ElementId) is IInputElement element)) { reply.ErrorMessages.Add("Could not find element"); return; } if (element is DependencyObject @do && Window.GetWindow(@do) is Window window) { if (!ActivateWindow(window)) { reply.ErrorMessages.Add($"Failed to activate window."); return; } }