views:

307

answers:

1

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 1st item of the child List Box It focus repeteadly(as it get repeated inside parent Listbox) on 1st all the 1st items of parentlistbox, wish I could have provide a Screen shot for Better Understanding. But Can't

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

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

Thanks, Subhen

A: 

It's difficult to determine what you're trying to accomplish in your code.

One idea: Have you considered changing the inner ListBox to an ItemsControl? If you needed it to scroll as well, you could layer it in a ScrollViewer.

Second idea (possibly an additional idea): Every item that created in the item template is calling the Loaded event. Don't you want that to happen only once? Remove the event from the inner ListBox and set focus once the outer list has been loaded.

WPCoder
I need my inner listbox to scroll and selectable. Just imagine a Music Player , where the Main List Box will contain lets say Picture of Music album, and it will contain a data template which will conatin another listbox. Now this List box will contain , all the songs related to that artist. Now when the page loads ,(continued in next comment ...)
Subhen
the focus wil be set on the 1st Song(1st Item of inner list box) of 1st artist(MainList Box 1st Item) and on click of next button it should select 2nd song(2nd Item of inner list box) of 1st artist(MainList Box 1st Item) and onwards. Here I gues list box is the only control that is going to help in this scenario.
Subhen