Home > DeveloperSection > Forums > WPF: ListBox with WrapPanel, vertical scrolling problem
Ankit Singh

Total Post:341

Posted on    September-25-2013 2:58 AM


 1 Reply(s)
 7677  View(s)
Rate this:

I have a UserControl (XAML below) that has a ListBox that I want to display images inside a WrapPanel, where images are displayed as many as will fit on one row and then wrap onto the next row etc. It works, except when the ListBox grows higher than the available space in the window, I'm not getting a vertical scrollbar, i.e. the contents get clipped. If I set a fixed height on the ListBox, the scrollbar appears and works as expected. How can I get this listbox to grow to the available space and then show a vertical scrollbar? This control is inside StackPanel inside a Grid in the main window. If I wrap the StackPanel inside a ScrollViewer, I get the scrollbar I'm after, but that's not really a good solution if I wanted to add some more controls to the UserControl above the ListBox (e.g. image size "zoom" etc) as I wouldn't want them to scroll with the images.

Thanks!! :)

<UserControl x:Class="GalleryAdmin.UI.GalleryView"



    <ListBox Name="itemListBox" BorderThickness="0" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">



                <StackPanel Background="LightGray" Margin="5" >

                    <StackPanel Margin="5">

                        <Image Source="{Binding Path=LocalThumbPath}" Height="100" />

                        <TextBlock Text="{Binding Path=Name}" TextAlignment="Center"></TextBlock>







                <WrapPanel />




ezra heywood
ezra heywood

Total Post:145

Posted on    September-25-2013 4:23 AM

Hi Ankit,

Well, I finally stumbled upon the solution. I was adding my UserControl to a placeholder panel that looked like this:

            <ScrollViewer Margin="20" >

                <StackPanel Name="contentPanel"></StackPanel>


However, when I switched it to a Grid instead, things started to work the way I wanted:

<Grid Name="contentPanel" Margin="20" />

I think it has to do with the StackPanel not taking up all the vertical space by default, like the Grid is doing.

Don't want to miss updates? Please click the below button!

Follow MindStick