Reputation: 3136
I have a listbox contained within a usercontrol. When set to Horizontal orientation it scrolls as expected but when I change this to vertical the selected item carries on changing down the list as I press the down key on the keyboard, but nothing scrolls so you can no longer see the selected item. It basically just disappears off the bottom of the screen.
The page layout has a Grid with a border around it which doesn't go off screen. Within this grid is a ContentControl
<Grid Grid.Column="1" Margin="0,30,30,30" Opacity=".7">
<Border BorderBrush="#FFFFFFFF" BorderThickness="2,2,2,2" CornerRadius="4,4,4,4" >
<Border.Effect>
<BlurEffect KernelType="Gaussian" Radius="4"/>
</Border.Effect>
</Border>
<Grid Background="Black">
<ContentControl Content="{Binding SelectedSettingViewModel}" Focusable="False" />
</Grid>
</Grid>
Within this contentcontrol is a usercontrol. Inside the usercontrol is the listbox that I am having issues with.
<UserControl>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Controls:KNListBox Grid.Row="4" x:Name="SettingsListBox" KeyboardNavigation.DirectionalNavigation="Continue" ItemsSource="{Binding AutoCompleteDirectories}"
Style="{DynamicResource SettingsListBox}" SelectedItem="{Binding SelectedAutoCompleteDirectory, Mode=TwoWay}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</Controls:KNListBox>
</Grid>
</UserControl>
I've tried changing the grid heights and removing the ListBox's Style but with no joy. Can anyone see where I am going wrong?
Upvotes: 2
Views: 660
Reputation: 3136
Fixed this by changing the row definition that contained the listbox from Auto to *. Auto was expanding the row to the size of the listbox, thus it would disappear off screen and never scroll.
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
Upvotes: 1