0

my main window consists of a Grid splitting it into two parts. in one of the parts i have a stackPanel. into the stackPanel i add via stackPanel.child.add(user control) (from the .cs file) the selected user control window

my question is: how do i make this one child added via the .cs fill the stackPanel completely?

Xaml code:

<StackPanel Name="myStkP" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" DockPanel.Dock="Bottom"/>

.cs code:

firstAttempt fat = new firstAttempt();
this.myStkP.Children.Add(fat);

firstAttempt is the user control (wpf) i created

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Gal Sheldon
  • 83
  • 1
  • 8
  • 1
    See: http://stackoverflow.com/questions/569095/how-to-get-stackpanels-children-to-fill-maximum-space-downward and http://stackoverflow.com/questions/9341940/fill-all-available-space-in-stackpanel -- In short: `DockPanel`. – BlackBox May 16 '15 at 19:47
  • A StackPanel is not designed to fill its parent, so even when the control is added to the stack panel, the stack panel itself is likely not filling up the part of the grid that it is in. Why are you using a StackPanel anyway if only filling it with one control? Try using a DockPanel as @BlackBox suggested. – User92 May 16 '15 at 20:28
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders May 16 '15 at 21:27

1 Answers1

0

The child element, fat, should also have VerticalAlignment="Stretch" HorizontalAlignment="Stretch"

Luc
  • 1,491
  • 1
  • 12
  • 21
  • the child added is a user control (wpf) class inside that class i also have a grid which is stretched. is it possible to put stretch in this line of code:? – Gal Sheldon May 16 '15 at 19:56