Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListBox with ItemTemplate (and ScrollBar!)

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.

like image 312
Pompair Avatar asked Jan 27 '09 14:01

Pompair


2 Answers

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.

like image 122
Muad'Dib Avatar answered Nov 13 '22 02:11

Muad'Dib


ListBox will try to expand in height that is available.. When you set the Height property of ListBox you get a scrollviewer that actually works...

If you wish your ListBox to accodate the height available, you might want to try to regulate the Height from your parent controls.. In a Grid for example, setting the Height to Auto in your RowDefinition might do the trick...

HTH

like image 10
Arcturus Avatar answered Nov 13 '22 01:11

Arcturus