Horizontal stack patch

Is it possible to have a <StackPanel> or label (or button, no matter what) horizontally intersects its parent control (e.g. Window ) and does it fill all the valid space?

For example, if I had 3 controls

_ window width _

[1] __ [2] __ [3]

or 2 controls

_ window width _

[1] _______ [2]

in each case, the full width of the window is used, with each left and right control being aligned accordingly.

+7
source share
2 answers

The StackPanel will stack the controls, so there is no short answer. This is not what the StackPanel is designed for.

You can use the grid as Vlad suggested. Something like that:

  <Grid HorizontalAlignment="Stretch"> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="auto"/> </Grid.ColumnDefinitions> <Button Width="20" Height="20" Grid.Column="0"/> <Button Width="20" Height="20" Grid.Column="2"/> <Button Width="20" Height="20" Grid.Column="4"/> </Grid> 
+15
source
  StackPanel m_pstackpanel = (StackPanel)this.Parent; m_pstackpanel.Children.Clear(); keypadclasslist keypadWindow = new keypadclasslist(m_pLstReceiver); m_pstackpanel.Children.Add(keypadWindow); 
-3
source

All Articles