WPF WrapPanel / ItemsControl not scrolling

Kaya picture Kaya · May 27, 2010 · Viewed 7.2k times · Source

I have a wrap panel displaying items but I cant get a scroll bar to work properly any idea's whats wrong ?

       <ScrollViewer>
        <ItemsControl Name="itemsControl">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel ItemWidth="{Binding ElementName=sizeSlider, Path=Value}" 
                                   FlowDirection="LeftToRight"  Height="auto" Width="auto"
                                   HorizontalAlignment="Left" Name="wrapPanel1" 
                                   VerticalAlignment="Top"
                                   Margin="5"
                               >
                    </WrapPanel>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
    </ScrollViewer>
</StackPanel>

Answer

repka picture repka · May 27, 2010

Your ScrollViewer is inside StackPanel which resizes to its content (either vertically or horizontally depending on its orientation). Place it either directly in a Window, a cell of a Grid, or a DockPanel for scroll bars to show up.