1
votes

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

2
ListBox does not restrict its items height if vertical scroll is enabled so your ListView item can grow as high as it needs to to accommodate all items therefore you'll never see scroll bar on your ListView item. Why scroll bar does not appear on ListBox is different question. It seems that somewhere up the visual tree (one of ListBox parents) is another panel that does not restrict its children height like StackPanel or Canvas - dkozl

2 Answers

1
votes

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

0
votes

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

<ListView ScrollViewer.CanContentScroll="True" 
 Scro