Hello,
I just started working with WPF and did not find the answer to my question in Google, so please do not throw stones.
So, I place the blocks in the WrapPanel, so that they would line up as needed after resizing the window:

<WrapPanel> <StackPanel> <WrapPanel> <GroupBox Header="Block1" VerticalAlignment="Top"> <StackPanel Width="200" Height="50" Background="Gray"/> </GroupBox> <GroupBox Header="Block2"> <StackPanel Width="200" Height="150" Background="LightBlue"/> </GroupBox> <GroupBox Header="Block3"> <StackPanel Width="200" Height="25" Background="LightCoral"/> </GroupBox> </WrapPanel> </StackPanel> </WrapPanel> 

If the window is of normal size, the blocks are arranged as it should: Window, normal condition

If, however, this window is enlarged, it turns out like this: Window, magnified state, not the right view

And it is necessary like this:

Window, enlarged state, desired display

What can be done? Which way to dig?
Thank you very much!

UPDATE:

I found this answer: https://stackoverflow.com/questions/24158561/how-to-appose-wrappanel-items-of-different-heights-vertically , but someone’s library is used there. Is it really impossible to do such a standard?

  • Probably in the direction of the Grid and the code, which, when resizing the window, knowing the size of the elements will shift them as it should. - vitidev
  • one
    In principle, it’s very easy to write the right container by hand. If I don't forget, I'll write an example next week. Here from the existing: .stackoverflow.com/a / 549816 / 10105 . - VladD

1 answer 1

Yes, as correctly written on your link in the standard WPF there is no such possibility. Unfortunately. But there is nothing wrong with using libraries from other developers!

Because There is currently no NuGet package (you can offer to do this in an issue on github :)) then you will need to download the sources and compile the .dll yourself.

I will add an example for your code:

 <Masonry:MasonryControl> <GroupBox VerticalAlignment="Top" Header="Block1"> <StackPanel Width="200" Height="50" Background="Gray" /> </GroupBox> <GroupBox Header="Block2"> <StackPanel Width="200" Height="150" Background="LightBlue" /> </GroupBox> <GroupBox Header="Block3"> <StackPanel Width="200" Height="25" Background="LightCoral" /> </GroupBox> </Masonry:MasonryControl> 

Display:

http://0s.ne.on2gcy3l.nfwwo5lsfzrw63i.nblz.ru/VYQKC.jpg