Question: I am facing the following issue. When i am removing the first element from a list box which has keyboard focus(by refreshing the item source) the keyboard focus is moving to the parent window. I want to retain the keyboard focus on the fist listbox item. So i came up with the following code

```
<Grid.Resources>
<Style TargetType="{x:Type ListBox}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding FirstRowDeleted}" Value="True">
            <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=MyListBox}" />
        </DataTrigger>
    </Style.Triggers>
</Style>

```

Using this code i am able to move the focus to the list box itself. How can i move the focus to the first listbox item? MyListBox[0] does not seem to work. Any suggestions?

Thanking you
Kaddy

Answer: 
I found answer here: [How do you programmatically set focus to the SelectedItem in a WPF ListBox that already has focus?](https://stackoverflow.com/questions/10444518/how-do-you-programmatically-set-focus-to-the-selecteditem-in-a-wpf-listbox-that)

```
var listBoxItem = (ListBoxItem) MainListBox
    .ItemContainerGenerator
    .ContainerFromItem(MainListBox.SelectedItem);
listBoxItem.Focus();

```

Thanks for @Jeff for the answer.
This code applies the focus function to the first input text when the page loads. try it out

```
$(document).ready(function () {

                $("#input:text:visible:first").focus();

            });

```