Reputation: 1233
I defined a Window in WPF, into this one I put a "stack panel" and inside this panel I put a "tab control" and some "button controls".
When executing the program, I would like that when I have to resize the window using the mouse, the stack panel and all controls inside it can also be resized automatically and proportionally to the window.
How can I get this?
Thanks!!
Upvotes: 1
Views: 700
Reputation: 57919
If you want everything to just scale up and down uniformly, so you might end up with giant or tiny controls and fonts, wrap the entire window contents (currently, the StackPanel
) in a Viewbox
control.
Upvotes: 0
Reputation: 172270
A StackPanel
only uses the space that its child controls need; it does not resize to the available space of the window.
If you want this behavior, use a different type of panel: If you only want the tab control to resize, use a DockPanel
and make the tab control the last child of the DockPanel. A DockPanel stretches to the available space of the parent, with the last child getting all the space not used by the previous children.
<DockPanel>
<Button DockPanel.Dock="Bottom" />
<Button DockPanel.Dock="Bottom" />
<TabControl>
...
</TabControl>
</DockPanel>
If you need more complex spacing behavior (for example, you want the Buttons to proportionally take up more space as well), have a look at the Grid
control.
Upvotes: 1