OOB textbox focus

4 posts, 0 answers
  1. James B.
    James B. avatar
    24 posts
    Member since:
    Jan 2011

    Posted 03 Jul 2012 Link to this post

    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();
  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 06 Jul 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. James B.
    James B. avatar
    24 posts
    Member since:
    Jan 2011

    Posted 06 Jul 2012 Link to this post

    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.
  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 09 Jul 2012 Link to this post

    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 >>

Back to Top