This is a migrated thread and some comments may be shown as answers.

OOB textbox focus

3 Answers 45 Views
Window
This is a migrated thread and some comments may be shown as answers.
James B.
Top achievements
Rank 1
James B. asked on 03 Jul 2012, 08:36 PM
Can't get cursor focus on a radwindow in SL5 OOB app. It's a popup from the mainpage.

Trying this in window_Loaded event.

UpdateLayout();
txtField.Focus();

3 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 06 Jul 2012, 02:39 PM
Hello James,

To set the focus on a control you need to make sure that the control you want to be focused is loaded before setting the focus on it. Here is a sample method that puts the focus on the passed focusControl:

private void PutFocus(Control focusControl)
{
    if (focusControl != null)
    {
        RoutedEventHandler loadedEventHandler = null;
        loadedEventHandler = new RoutedEventHandler(delegate
        {
            focusControl.Loaded -= loadedEventHandler;
            focusControl.Focus();
        });
        focusControl.Loaded += loadedEventHandler;
    }
}

Hope this helps.

Kind regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
James B.
Top achievements
Rank 1
answered on 06 Jul 2012, 08:21 PM
Thanks for the code. It still isn't working for me. The control is in the xaml and the window only has 1 field and 2 buttons so not sure what's up.
0
Vladi
Telerik team
answered on 09 Jul 2012, 11:36 AM
Hi James,

I have prepared and attached a sample project representing the described approach on how to set the focus on specific control. In the attached project the focus is set to textBox2.

Take a look at it and tell me if you are doing something different in your project.

Kind regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Window
Asked by
James B.
Top achievements
Rank 1
Answers by
Vladi
Telerik team
James B.
Top achievements
Rank 1
Share this question
or