<p>Some WPF controls (like the <code>Button</code>) seem to happily consume all the available space in its' container if you don't specify the height it is to have.</p>

<p>And some, like the ones I need to use right now, the (multiline) <code>TextBox</code> and the <code>ListBox</code> seem more worried about just taking the space necessary to fit their contents, and no more. </p>

<p>If you put these guys in a cell in a <code>UniformGrid</code>, they will expand to fit the available space. However, <code>UniformGrid</code> instances are not right for all situations. What if you have a grid with some rows set to a * height to divide the height between itself and other * rows? What if you have a <code>StackPanel</code> and you have a <code>Label</code>, a <code>List</code> and a <code>Button</code>, how can you get the list to take up all the space not eaten by the label and the button?</p>

<p>I would think this would really be a basic layout requirement, but I can't figure out how to get them to fill the space that they could (putting them in a <code>DockPanel</code> and setting it to fill also doesn't work, it seems, since the <code>DockPanel</code> only takes up the space needed by its' subcontrols).</p>

<p>A resizable GUI would be quite horrible if you had to play with <code>Height</code>, <code>Width</code>, <code>MinHeight</code>, <code>MinWidth</code> etc. </p>

<p>Can you bind your <code>Height</code> and <code>Width</code> properties to the grid cell you occupy? Or is there another way to do this?</p>

[{'answer_id': 36184, 'author': 'Rune Jacobsen', 'author_id': 2122, 'author_profile': 'https://Stackoverflow.com/users/2122', 'pm_score': 5, 'selected': False, 'text': '<p>Well, I figured it out myself, right after posting, which is the most embarassing way. :)</p>\n\n<p>It seems every member of a StackPanel will simply fill its minimum requested size.</p>\n\n<p>In the DockPanel, I had docked things in the wrong order. If the TextBox or ListBox is the only docked item without an alignment, or if they are the last added, they WILL fill the remaining space as wanted.</p>\n\n<p>I would love to see a more elegant method of handling this, but it will do.</p>\n'}, {'answer_id': 36634, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 8, 'selected': False, 'text': '<p>There are also some properties you can set to force a control to fill its available space when it would otherwise not do so. For example, you can say:</p>\n\n<pre><code>HorizontalContentAlignment="Stretch"\n</code></pre>\n\n<p>... to force the contents of a control to stretch horizontally. Or you can say:</p>\n\n<pre><code>HorizontalAlignment="Stretch"\n</code></pre>\n\n<p>... to force the control itself to stretch horizontally to fill its parent.</p>\n'}, {'answer_id': 36741, 'author': 'user3837', 'author_id': 3837, 'author_profile': 'https://Stackoverflow.com/users/3837', 'pm_score': 8, 'selected': True, 'text': '<p>Each control deriving from <strong><code>Panel</code></strong> implements distinct layout logic performed in <code>Measure()</code> and <code>Arrange()</code>:</p>\n\n<ul>\n<li><code>Measure()</code> determines the size of the panel and each of its children</li>\n<li><code>Arrange()</code> determines the rectangle where each control renders</li>\n</ul>\n\n<p>The last child of the <strong><code>DockPanel</code></strong> fills the remaining space.  You can disable this behavior by setting the <code>LastChild</code> property to <code>false</code>.</p>\n\n<p>The <strong><code>StackPanel</code></strong> asks each child for its desired size and then stacks them.  The stack panel calls <code>Measure()</code> on each child, with an available size of <code>Infinity</code> and then uses the child\'s desired size. </p>\n\n<p>A <strong><code>Grid</code></strong> occupies all available space, however, it will set each child to their desired size and then center them in the cell.</p>\n\n<p>You can implement your own layout logic by deriving from <code>Panel</code> and then overriding <code>MeasureOverride()</code> and <code>ArrangeOverride()</code>.</p>\n\n<p>See <a href="https://learn.microsoft.com/en-us/dotnet/framework/wpf/controls/how-to-create-a-custom-panel-element" rel="noreferrer">this article</a> for a simple example.</p>\n'}, {'answer_id': 36750, 'author': 'urini', 'author_id': 373, 'author_profile': 'https://Stackoverflow.com/users/373', 'pm_score': 3, 'selected': False, 'text': '<p>Use the <strong>HorizontalAlignment</strong> and <strong>VerticalAlignment</strong> layout properties. They control how an element uses the space it has inside its parent when more room is available than it required by the element.</p>\n\n<p>The width of a StackPanel, for example, will be as wide as the widest element it contains. So, all narrower elements have a bit of excess space. The alignment properties control what the child element does with the extra space.</p>\n\n<p>The default value for both properties is Stretch, so the child element is stretched to fill all available space. Additional options include Left, Center and Right for <strong>HorizontalAlignment</strong> and Top, Center and Bottom for <strong>VerticalAlignment</strong>.</p>\n'}]
['https://Stackoverflow.com/questions/36108', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2122/']