1

If I have a list of Cars bound to a ListBox. I now want to implement that the first item is initially focused, additionally I want to implement a full keyboard navigation between the displayed ListBox-items, therefore I need access to the virtually created item controls.

The problem is that itemStack.Items[i] returns the Car itself and not the CarEditControl. How can I get the virtually created item?

   <ObjectDataProvider x:Key="ItemSource" d:IsDataSource="True"/>

    <ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
        <StackPanel IsItemsHost="True"/>
    </ItemsPanelTemplate>

    <DataTemplate x:Key="ItemCollectionTemplate">
        <StackPanel>
            <custom:Item x:Name="item" Car="{Binding Path=.,Mode=OneWay}" />
        </StackPanel>
    </DataTemplate>
codymanix
  • 28,510
  • 21
  • 92
  • 151
  • 1
    This answer is for ListView, but the code is essentially the same: http://stackoverflow.com/questions/2789408/how-to-focus-on-listviewitem-in-wpf – Matt Hamilton Jan 31 '11 at 00:33
  • Thanks, matt this works. Another question. Is there a way to enumerate all item controls or invoke an event on all item controls? – codymanix Feb 05 '11 at 16:41
  • @Matt Hamilton: Repost that as answer please. – H.B. Jun 14 '11 at 00:55
  • @codymanix: No, you need to use some kind of loop (`for`/`foreach`). – H.B. Jun 14 '11 at 00:56
  • @H.B. As much as I'd love the extra 15 reputation points, I think it's better if we close this as a duplicate so people are directed to the existing answer. I will vote to close. – Matt Hamilton Jun 14 '11 at 02:17
  • @Matt Hamilton: Probably not going to reach the needed vote count but one can try. – H.B. Jun 14 '11 at 02:22

0 Answers0