-3

I am adding few controls dynamically to a virtualizing stack panel control as children. I would like to wrap controls to next row if the controls don't fit in a row. How can I do that?

If I use Wrappanel then Virtualization will not happen.

So in short I need the same wrap panel functionality using StackPanel

user3722329
  • 5
  • 1
  • 4
  • Does it answer your question https://stackoverflow.com/questions/10146428/wrapping-content-in-a-stackpanel-wpf#:~:text=6%20Answers&text=Create%20nested%20StackPanel%20s%20which,horizontally%20next%20to%20each%20other. – Tony Stark May 21 '21 at 04:42
  • @TonyStark This will not help as the number of controls are not fixed on a row. They should get shift on window resize. – user3722329 May 21 '21 at 05:08
  • You're barking up the wrong tree. Getting `StackPanel` to wrap would mean it would have to understand stacking both horizontally and vertically at the same time. It doesn't, and I doubt there's any practical way to change that. What you actually want is a virtualizing `WrapPanel`. See duplicates. That said, I'd argue that if you have so many elements that you want virtualization, then `WrapPanel` is probably the wrong view to present to the user in the first place. – Peter Duniho May 21 '21 at 05:30

1 Answers1

1

You can use like this,

enter image description here

<WrapPanel Orientation="Horizontal">
<Button Content="Button" />
<Button Content="Button" />
<Button Content="Button" />
<Button Content="Button" />
<Button Content="Button" />
</WrapPanel>
Tony Stark
  • 434
  • 4
  • 13