How to focus the templated dropdown content when drop down opened?

4 posts, 1 answers
  1. xu
    xu avatar
    14 posts
    Member since:
    Feb 2012

    Posted 05 Apr 2012 Link to this post

    Hi,

    I'm using the RadDropDownButton with a drop down content template to show a UserControl. I want the UserControl get focused on dropdown opened. I've tried the following code, but the DropDownContent property always return null.

    dropDownBtn.DropDownOpened += (o, e) => 
    {
        (dropDownBtn.DropDownContent as UserControl).Focus();
    };
    Help me please!

  2. Answer
    Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 06 Apr 2012 Link to this post

    Hello,
    If you're using UserControl as a DropDownContent of your DropDownButton you can handle the Loaded event of the UserControl and get the focus there:
    private void MyUserControlLoaded(object sender, RoutedEventArgs e)
    {
        this.Focus();
    }
    I've attached a sample project with this code so you could test it and if you have more questions please feel free to ask.

    Kind regards,
    Zarko
    the Telerik team

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

  3. DevCraft banner
  4. xu
    xu avatar
    14 posts
    Member since:
    Feb 2012

    Posted 09 Apr 2012 Link to this post

    Thanks,that  works for me. But I'm just wandering why doesn't the RadDropDownButton focus the drop down content automaticly, so the user can use keyborad without any interuption.
  5. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 12 Apr 2012 Link to this post

    Hello,
    I'm glad that we were able to help you. As for the default behavior of the RadDropDownButton - we think that this is the expected behavior and also it's easier to manually focus the DropDownContent than to unfocus it (if this is the default behavior) and that's why we've made it this way.
    If you have further questions please feel free to ask.

    Regards,
    Zarko
    the Telerik team

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

Back to Top