0

I have a Window that has a UserControl. What i want to accomplish is Bind the ActualHeight of the StackPanel (stackpanel doesn't have a fixed size) that contains the UserControl in order to achive the correct behavior of the WrapPanel inside the UserControl.

I've tried Height="{Binding ElementName=MyStackPanel, Path=ActualHeight}" and Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=ActualHeight}" but it didn't worked.

The way i place the UserControl inside the Window's StackPanel is as follows:

     <StackPanel x:Name="MyStackPanel" Orientation="Vertical">
         <!-- Wrap Panel / UserControl-->
         <local:WrapControl />
     </StackPanel>

If it helps the Main Window is a devexpress DXRibbonWindow.

Zoti
  • 822
  • 11
  • 31
  • Is `MyStackPanel` identical to `stkTop`? The Height of which control do you want to bind? It's unclear what exactly you are trying to achieve. Please add some details. – Clemens Apr 03 '15 at 12:26
  • yes. i am sorry...i will correct it. – Zoti Apr 03 '15 at 12:32
  • Still not clear which Height you want to bind, i.e. at which control you tried to set `Height="{Binding ...}`. – Clemens Apr 03 '15 at 12:36
  • I've tried to bind with `MyStackPanel`'s height. The `WrapControl` has a `WrapPanel` with some `Expanders` inside it. So i just want to move the expanders that doesn't fit when they expand, to the right. I've tried to set `Height=...` to the `WrapPanel` inside my `WrapControl` `UserControl`. – Zoti Apr 03 '15 at 12:47
  • The `WrapPanel`'s `Height`. – Zoti Apr 03 '15 at 12:51
  • As long as the StackPanel does not vertically stretch to the size of its parent (the Window?), its ActualHeight will be determined by the sum of the ActualHeights of its Children. So it doesn't make sense to set the Height of the WrapPanel to the ActualHeight of the StackPanel. Try to set the VerticalAlignment properties of the panels instead. You may also try to use a Grid instead of the StackPanel, because it stretches its Children by default. – Clemens Apr 03 '15 at 12:57
  • I found the solution. Thank you @Clemens. – Zoti Apr 03 '15 at 13:00

1 Answers1

0

Ok so it seems that StackPanel has no concept of "stretching" to occupy all the space available.

Replacing the StackPanel with a Grid works perfect.

Zoti
  • 822
  • 11
  • 31
  • You don't need that binding. The Grid stretches its child elements by default (unless you change their HorizontalAlignment or VerticalAlignment). – Clemens Apr 03 '15 at 13:02