Set Focus

4 posts, 0 answers
  1. Rieni De Rijke
    Rieni De Rijke avatar
    170 posts
    Member since:
    Mar 2010

    Posted 23 Sep 2010 Link to this post

    We have a RadDateTimePicker in a window.
    When the window opens, we want to set focus on the RadDateTimePicker.
    So we use 
             public OurWindow()
            {
                InitializeComponent();
                OurDateTimePicker.Focus();
            }
    When openeing the window, we see the orange border (Office-theme) that indicates that the RadDateTimePicker has focus. When pushing the Arrow-Down-key the calendar opens. Great!
    But, our customers also want the possibility to can write immediately in the box. How could we do this?
    When we set focus from codebehind, the text in the box is not selected and there is no beam in the box.

    We alse tried to set focus after the window was loaded and activated. 
  2. George
    Admin
    George avatar
    1332 posts

    Posted 28 Sep 2010 Link to this post

    Hello,

    Thank you for contacting us.

    To accomplish this, I would suggest you to use FindChildrenByType<>  method to find the TextBox, placed in the RadDateTimePicker control. Then, you could set the focus to this TextBox. For example:

    var textbox = this.picker.FindChildByType<TextBox>();
                if (textbox != null)
                {
                    textbox.Focus();
                }

    Attached you can find the sample project. I hope this helps!


    All the best,
    George
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Maurizio
    Maurizio avatar
    1 posts
    Member since:
    Sep 2014

    Posted 21 May 2015 in reply to George Link to this post

    When I'm trying to give the focus to a RadDatePicker that is becoming visible for the first time, it happens that the textbox I am looking for (with FindChildByType) is null, probably because wpf is still in the process of creating it.

    I even tried to delay the Focus using the dispatcher but nothing has changed.

    After the first time the RadDatePicker has become visible, setting the focus works correctly.

  5. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 26 May 2015 Link to this post

    Hi Maurizio,

    We tested the proposed by George approach using the latest official released version 2015.1.401 and the Loaded event of RadDateTimePicker and it seems everything works as expected. Using the ChildrenOfType method we could get the TextBox and by using its Focus method the focus is set as expected:
    private void radDateTimePicker_Loaded(object sender, RoutedEventArgs e)
    {
        var dateTimePicker = sender as RadDateTimePicker;
     
        var textBox = dateTimePicker.ChildrenOfType<TextBox>().FirstOrDefault();
        textBox.Focus();
    }

    Could you please give a try again to the proposed approach using the provided above code - snippet and let us know if it worked for you?

    Hopes this helps.

    Regards,
    Nasko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top