textBox embedded in a ListBox initial focus
问题 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(); } 回答1: it's stupid but it works only if you wait a moment, try this version: using System; using System.Windows; using System.Windows.Controls; namespace