AutoCompleteBox cannot set focus on load

Editors for WPF Forum

Posted 7 years ago by Mike
Version: 17.2.0665
Platform: .NET 4.7
Environment: Windows 10 (64-bit)
Avatar

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)

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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

The latest build of this product (v24.1.3) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.