WPF: WrapPanel in ItemsPanelTemplate expands list width WPF: WrapPanel in ItemsPanelTemplate expands list width wpf wpf

WPF: WrapPanel in ItemsPanelTemplate expands list width


Set ScrollViewer.HorizontalScrollBarVisibility="Disabled" and the WrapPanel will wrap.

<Grid>    <ListBox        ScrollViewer.HorizontalScrollBarVisibility="Disabled">        <ListBox.ItemsPanel>            <ItemsPanelTemplate>                <WrapPanel />            </ItemsPanelTemplate>        </ListBox.ItemsPanel>    </ListBox></Grid>


I've solved the problem.. the problem was (probably) that some of the containers that contained my listbox was a little too generous with allocating space for my listbox.In any case, as soon as I removed the scrollbar for the rest of my containers (that contains my list), it works as expected. :)

Thanks for your reply, it was very helpful in solving this.


Normally it won't wrap as you expect until you set the Horizontal scroll bar to disabled. Now you have a wrappanel that actually wraps :)

ScrollViewer.HorizontalScrollBarVisibility="Disabled"