0

I have a ListBox in my xaml file which looks like this:

<ListBox Name="collateralPledgedListbox" 
         Style="{StaticResource USB_ListBox}" 
         Margin="0,0,5,39" Width="Auto"  
         ItemsPanel="{StaticResource USB_ListBox_ItemPlacement}"  
         TabNavigation="Local"  
         ItemContainerStyle="{StaticResource USB_ListBoxContainer}"  
         ItemsSource="{Binding Model.CollateralPledgedByMarriedIndividuals, Mode=TwoWay}"  
         ItemTemplate="{StaticResource USBcollateralColSumColInfoDataTemplate}"  
         ScrollViewer.HorizontalScrollBarVisibility="Hidden"> 
</ListBox>

This ListBox shows a vertical scroll bar when there are number of rows exceed the provided space. I am not able to show the currently selected row to the user while tabbing through the controls within the ListBox.

I am using C# as my language. Any help on this would be appreciated.

Noctis
  • 11,507
  • 3
  • 43
  • 82
Kunal Nair
  • 93
  • 2
  • 8

1 Answers1

0

Sounds like all you have to do is set your focus and refresh your view. Have you tried doing what this answer suggests?

private void Button_Click(object sender, RoutedEventArgs e)
{
  MainListBox.SelectedItem = MainListBox.Items[3];
  MainListBox.UpdateLayout(); // Pre-generates item containers 

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

  listBoxItem.Focus();
}
Community
  • 1
  • 1
Noctis
  • 11,507
  • 3
  • 43
  • 82