Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal Orientation in Stackpanel, new line at the end of Stackpanel width

Let's say that we have a Stackpanel with Horizontal Orientation and a width of 100px.

Inside it i make eleven square Canvas drawings width the size of 10px.

This means that the last square will be outside of view, because it will extend the stackpanel width 10px. So I want this square to be in a new line.

Is there a Control that can do this? The hard part is that the Stackpanel will be dynamic, so if i Resized the WPF window, the Stackpanel will be 50px, wich will result in 2 full square lines and a third line with a single square.

I hope this makes sence. How can I do this?

Thanks, Jonatan

like image 528
Jonatan Grim Avatar asked Mar 25 '15 15:03

Jonatan Grim


People also ask

How do you draw a horizontal line in WPF?

To draw a line, create a Line element. Use its X1 and Y1 properties to set its start point; and use its X2 and Y2 properties to set its end point. Finally, set its Stroke and StrokeThickness because a line without a stroke is invisible. Setting the Fill element for a line has no effect, because a line has no interior.

What is the difference between StackPanel and DockPanel?

StackPanel vs. For example, the order of child elements can affect their size in a DockPanel but not in a StackPanel. This is because StackPanel measures in the direction of stacking at PositiveInfinity, whereas DockPanel measures only the available size. The following example demonstrates this key difference.

What is a StackPanel?

StackPanel is a layout panel that arranges child elements into a single line that can be oriented horizontally or vertically. By default, StackPanel stacks items vertically from top to bottom in the order they are declared. You can set the Orientation property to Horizontal to stack items from left to right.


1 Answers

Wrap panel is what you need in this case

    <WrapPanel  Width="100" Orientation="Horizontal">
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
        <Button   Width="10" Height="20"/>
    </WrapPanel>
like image 118
Muds Avatar answered Oct 05 '22 12:10

Muds