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
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With