Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Window set Focus

I have a WPF Window which I only create one time and then Show() and Hide() several times. Now I am searching a way to set the focus on a element on each Show(). Where and how can I do this?

like image 416
BennoDual Avatar asked Jun 18 '11 11:06

BennoDual


People also ask

What is focus() method in c#?

The Focus method returns true if the control successfully received input focus. The control can have the input focus while not displaying any visual cues of having the focus. This behavior is primarily observed by the nonselectable controls listed below, or any controls derived from them.

How do I center a window in WPF?

To open a new window and have it centred on the screen, set the WindowStartupLocation property to CenterScreen. You can do this using the XAML or in code before the window is displayed. Run the program and click the button to see the result.


1 Answers

Just call Element.Focus() on the element you want to focus.

If you mean bring focus to the window try calling window.Activate()

like image 197
Cilvic Avatar answered Sep 28 '22 01:09

Cilvic