WPF: WrapPanel in ItemsPanelTemplate extends list width

I have a list defined as follows:

                                                  

    <ListBox.ItemTemplate>
        <DataTemplate>
            <ItemsControl>
                <!-- Contents here -->
            </ItemsControl>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

My problem is this: this list is contained in the grid control and should use all the available space of this cell in which it is contained, but it should not force the parent to allocate MORE space. But what happens is that after the wrapping panel is full, instead of actually wrapping the elements on the next line (as it should be), it simply expands the width of the list, and in the process also forces the parent grid to be resized.

How can I make the crawl panel respect the size of my parent, rather than force it to expand its size?

Thanks in advance!

edit: . , , , , .

+5
4

ScrollViewer.HorizontalScrollBarVisibility="Disabled" WrapPanel.

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

. () , , , , . , ( ), , .:)

, .

0

(Blend VS 2013), , :

: DesignHeight = "300" : DesignWidth = "600"

0

Usually it will not wrap as you expect until you set the horizontal scroll bar to turn off. Now you have a wrapper that actually wraps :)

ScrollViewer.HorizontalScrollBarVisibility="Disabled"
0
source

All Articles