Problem

AutoCompleteBox cannot set focus on load

Posted 6 months ago by Avatar Mike

Hi,

I have a window with the autocompletebox and I'm trying to set the focus to it to it so the user can type right away. While it works on any control such as textbox it doesn't work on the autocompletebox.

 public TestWindow()
        {
            DataContext = this;
            InitializeComponent();
            autoCompleteBox.Text = "test";
            autoCompleteBox.Focus();
        }

 I always have to press TAB once to set the focus after the window has been created. Is there another way to set the focus to it?


Comments (1)

Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA

Hi Mike,

Thanks for letting us know about that.  We've fixed it for the next build, which will likely be the first 2018.1 build.  Even so, you will have to do the focus call in TestWindow.Loaded since the TextBox in the AutoCompleteBox's Template hasn't loaded yet at the time you call it above.

You could probably work around it in the current version by waiting until the control's template has loaded and then using our VisualTreeHelperExtended.GetDescendant method to locate the contained TextBox, and focus that.


Actipro Software Support
Information The latest build of this product (2018.1 build 0673) was released 1 month ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.