I want to set the focus to the first ListBox item that is a textbox. I want to be able to write in it immedatelly without the necesity to click it or press any key. I try this but doesn't work:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
listBox1.Items.Add(new TextBox() { });
(listBox1.Items[0] as TextBox).Focus();
}
it's stupid but it works only if you wait a moment, try this version:
I was testing locally and could not fix it until I found this question and fuzquat answer in there so vote me here and him there :D
Can't set focus to a child of UserControl
In case any body else has this issue. An UIElement has to be fully loaded before you can focus it. therefor this can be made very simple: