ListBox with ItemTemplate (and ScrollBar!)

Pompair picture Pompair · Jan 27, 2009 · Viewed 103.3k times · Source

I have a databound and itemtemplated ListBox:

<ListBox x:Name="lbLista" 
         ScrollViewer.VerticalScrollBarVisibility="Visible">
    <ListBox.ItemTemplate>
      <DataTemplate>
        <StackPanel Orientation="Horizontal">
          <CheckBox IsChecked="{Binding Deleteable, Mode=TwoWay}" />
          <Label Content="{Binding Name}" />
        </StackPanel>
      </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

The ites show fine and they come from an ObservableCollection.

The problem is the scrollbar which appears but is not usable - it does not have a handle to grab. I've tried setting some ScrollView attached properties on ListBox, but they do not affect the situation.

Answer

Muad&#39;Dib picture Muad'Dib · Jan 27, 2009

I pasted your code into test project, added about 20 items and I get usable scroll bars, no problem, and they work as expected. When I only add a couple items (such that scrolling is unnecessary) I get no usable scrollbar. Could this be the case? that you are not adding enough items?

If you remove the ScrollViewer.VerticalScrollBarVisibility="Visible" then the scroll bars only appear when you have need of them.