Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wrapping content in a StackPanel wpf

is it possible to wrap content in a StackPanel?

I know that we can make use of a WrapPanel instead. But for code modifying reasons, I must make use of a StackPanel.

So, is there a way to make the items in a StackPanel wrap after say 5 items... Thanks!

like image 472
user1202434 Avatar asked Apr 13 '12 18:04

user1202434


2 Answers

Create nested StackPanels which contain the required number of items.

In the example below, you have two rows, respectively occupied by the <StackPanel Orientation="Horizontal"> elements, which in turn each contain five items that will be displayed horizontally next to each other.

<StackPanel Orientation="Vertical">
    <StackPanel Orientation="Horizontal">
        <Item1 />
        <Item2 />
        <Item3 />
        <Item4 />
        <Item5 />
    </StackPanel>
    <StackPanel Orientation="Horizontal">
        <Item1 />
        <Item2 />
        <Item3 />
        <Item4 />
        <Item5 />
    </StackPanel>
</StackPanel>
like image 21
Douglas Avatar answered Oct 03 '22 00:10

Douglas


For me, a simple WrapPanel works just fine:

<WrapPanel Orientation="Horizontal" Width="500" />

Not inside a StackPanel or any other container. And setting Width to a constant value can be superior im some cases, because binding it to ActualWidth can prevent down-sizing (e.g. when parent control is down-sized, WrapPanel is not)

like image 198
bytecode77 Avatar answered Oct 02 '22 23:10

bytecode77