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.

1 Answer 1

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(); } 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply Noctis but this solution would not work as I do not know the index of the selected item.
could you sketch up your issue? I'm not sure what / why is the problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.