0

is there any way to obtain this layout using a WPF Wrappanel? B and C in the pictures should be vertically aligned in horizontal mode and horizontally aligned in vertical mode. Letters orientation must be preserved. In pictures, from [Horizontal] to [Vertical]:

Horizontal

Vertical

I've tryed:

<wrappanel>
<A/>
<wrappanel>
<B/><C/>
</wrappanel>
</wrappanel>

but its behaviuor is unpredictable. Thank you in advance.

11
  • Is there a reason not to use a Grid?
    – Clemens
    Commented Jan 14, 2020 at 10:03
  • Can't you just user Grid, set columns and rows, and set columnSpan/rowSpan on A to 2 ?
    – Zeronader
    Commented Jan 14, 2020 at 10:04
  • The unique way I've found: adding code in a SizeChanged event: if (this.Height > this.Width) {wrappanel.Orientation = Orientation.Horizontal} else {wrappanel.Orientation = Orientation.Vertical}
    – michele74c
    Commented Jan 14, 2020 at 10:08
  • @Clemens no: the Grid constrains B and C in rows or columns.
    – michele74c
    Commented Jan 14, 2020 at 10:13
  • @Zeronader the problem is not A, but B and C.
    – michele74c
    Commented Jan 14, 2020 at 10:13

1 Answer 1

0

If you just want to be in proper alignment, you can just use Grid like this. That way B and C will always have same width and height, whenever you resize window.

    <Grid>
   <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="*" />
   </Grid.ColumnDefinitions>
   <Grid.RowDefinitions>
      <RowDefinition Height="*" />
      <RowDefinition Height="*" />
   </Grid.RowDefinitions>
   <Button Content="A" Grid.Column="0" Grid.RowSpan="2" />
   <Button Content="B" Grid.Column="1" Grid.Row="0"/>
   <Button Content="C" Grid.Column="1" Grid.Row="1"/>
</Grid>
4
  • I've tryed, but this code always produces a left high button and two right ones. However, resizing does not bring to figure link...
    – michele74c
    Commented Jan 14, 2020 at 10:40
  • Oh, so you want to change from horizontal to vertical on resize? You should be more clear in your questions. You can also try using wrap panel, but keep B and C in grid and set minimalWidth on Grid or A, so 2nd item (which will be grid) will move to 2nd row in wrapPanel
    – Zeronader
    Commented Jan 14, 2020 at 10:43
  • if you use a grid or anything else, the first wrappanel will wrap the contained grid, but the contained objects won't wrap from horizontal to vertical, like in the image. The second wrappanel should solve this problem, but... this is the question. I don't know how to explain better, sorry
    – michele74c
    Commented Jan 14, 2020 at 10:51
  • Ok, so right now i can't figure out any solution without code, but with just a little code you can make converter which will convert entire window or A control width to orientation and set it on 2nd wrapPanel
    – Zeronader
    Commented Jan 14, 2020 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.