How to set keyboard Focus programmaticaly?

SyntaxEditor for WPF Forum

Posted 9 years ago by BERKANT ORAL
Version: 15.1.0621
Platform: .NET 4.5
Environment: Windows 8 (64-bit)
Avatar

I have a WPF application which uses Syntax Editor on demand. To achieve this, on some key event I create an instance of Syntax Editor and append it to children of a grid. Immediately I call editor.Focus() or editor.ActiveView.Focus(). In both scenarios the editor is getting focused but editor is not listening key strokes and caret is invisible.

How can I dynamically set keyboard focus to syntax editor and continue to edit without additional mouse clicks?

Thanks.

Comments (2)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

That should work fine but note that if you call Focus() on any WPF element before it's fully loaded in the UI, it won't properly accept focus.  Are you doing this after the UI is loaded?  If not, you could try doing a Dispatcher.BeginInvoke to move it into a Loaded priority.


Actipro Software Support

Posted 9 years ago by BERKANT ORAL
Avatar

Dispatcher Invoke solved my problem thanks.

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.