YWah
YWah

Reputation: 579

Listbox/listview vertical scrollbar does not show (horizontal yes)

I've a listbox defined in xaml like this:

<Grid.ColumnDefinitions>
  <ColumnDefinition Width="21" />
  <ColumnDefinition Width="*" />
  <ColumnDefinition Width="23" />
  <ColumnDefinition Width="23" />
  <ColumnDefinition Width="23" />
  <ColumnDefinition Width="4" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
  <RowDefinition Height="26" />
  <RowDefinition Height="*" />
  <RowDefinition Height="4" />
</Grid.RowDefinitions>


<ListBox x:Name="AInLb" Margin="8,6,8,8" BorderBrush="Gray" Grid.Row="1" Grid.ColumnSpan="6" Grid.RowSpan="2" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
  <ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
      <Setter Property="IsSelected" Value="{Binding Content.IsSelected, Mode=TwoWay, RelativeSource={RelativeSource Self}}"/> 
      <Setter Property="Template"> 
        <Setter.Value> 
          <ControlTemplate TargetType="ListBoxItem"> 
            <ContentPresenter/> 
          </ControlTemplate>
        </Setter.Value> 
      </Setter>
    </Style>
  </ListBox.ItemContainerStyle>
  <ListView x:Name="AInfoLv" FontFamily="Khmer UI" Background="White" BorderBrush="{x:Null}" BorderThickness="0" Foreground="Black">
    <ListView.View>
      <GridView>
        <GridViewColumn x:Name="LabelColumn" Header="Label" Width="110" DisplayMemberBinding="{Binding Path=Label}" />
        <GridViewColumn x:Name="ValueColumn" Header="Value" Width="140" DisplayMemberBinding="{Binding Path=Value}" />
      </GridView>
    </ListView.View>
    <ListView.ItemContainerStyle>
      <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="Template">
          <Setter.Value> 
            <ControlTemplate TargetType="{x:Type ListViewItem}">
              <Border BorderBrush="Transparent" BorderThickness="1" Background="{TemplateBinding Background}">
                <GridViewRowPresenter/> 
              </Border>
            </ControlTemplate> 
          </Setter.Value>
        </Setter> 
        <Style.Triggers>
          <DataTrigger Binding="{Binding Path=Label}" Value="Login"> 
            <Setter Property="FontWeight" Value="Bold"/> 
          </DataTrigger> 
          <DataTrigger Binding="{Binding Path=Label}" Value="Skill(s)">
            <Setter Property="FontWeight" Value="Bold"/> 
          </DataTrigger>
        </Style.Triggers>
      </Style>
    </ListView.ItemContainerStyle>
  </ListView>
</ListBox>

The height and width for both listbox and listview are set to auto. When the content exceeded the height and width of the listbox, the horizontal scrollbar works fine, but the vertical scrollbar does not show.

enter image description here

Update: Included @Dom's suggestion.

enter image description here

Update 2: After Height limit is set for the listbox.

enter image description here

Upvotes: 1

Views: 2838

Answers (2)

user5000935
user5000935

Reputation:

The ListView alreas a ScrollViewer. You need to enable it:

<ListView ScrollViewer.CanContentScroll="True" 
 Scro

Upvotes: 0

YWah
YWah

Reputation: 579

The problem solved by setting ScrollViewer.CanContentScroll="False" for the ListBox. Reference.

Upvotes: 1

Related Questions