How to Set focus on the 1st Item of Nested Listbox in Silverlight?

Posted by Subhen on Stack Overflow See other posts from Stack Overflow or by Subhen
Published on 2010-03-25T11:21:26Z Indexed on 2010/03/25 11:23 UTC
Read the original article Hit count: 550

Filed under:
|
|

Hi ,

I have a List box which contains another lisbox Inside it.

<ListBox x:Name="listBoxParent">
    <ListBox.ItemTemplate>

                        <DataTemplate>


                                    <Image x:Name="thumbNailImagePath" Source="/this.jpg"  Style="{StaticResource ThumbNailPreview}" />


                                        <TextBlock Margin="5" Text="{Binding Smthing}" Style="{StaticResource TitleBlock_Artist}" />
                                    </StackPanel>
                                    <StackPanel Style="{StaticResource someStyle}" >

                                        <ListBox x:Name="listBoxChild" Loaded="listBoxChild_Loaded" BorderThickness="0">
                                            <ListBox.ItemTemplate>
                                                <DataTemplate>
                                                    <StackPanel>
                                                        <TextBlock Margin="5" Text="{Binding myText}" Width="300"/>
                                                    </StackPanel>

                                                </DataTemplate>
                                            </ListBox.ItemTemplate>
                                        </ListBox>
                                    </StackPanel>

                        </DataTemplate>

                    </ListBox.ItemTemplate>
                    <ListBox.ItemsPanel>

                    </ListBox.ItemsPanel>

</ListBox>

Now while I try to focus to the child List Box :

 public void listBoxChild_Loaded(object sender, RoutedEventArgs e)
        {
           var myListBox = (ListBox)sender;

           myListBox .ItemsSource = PageVariables.eOUTData;//listboxSongsData;
           myListBox .SelectedIndex = 0;
           myListBox .Focus();
        }

Thanks, Subhen

© Stack Overflow or respective owner

Related posts about silverlight-3.0

Related posts about listbox