views:

81

answers:

2

Hello:

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!!

A: 

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.

Jay
Jay, Visual Studio does not allow me to wrap the StackPanel in the ViewBox.
@vizcaynot In what way doesn't it allow you? `<Viewbox><StackPanel>...</StackPanel></Viewbox>` is perfectly valid XAML -- I just tried it in VS2008 SP1. Make sure you're not trying to wrap the `<Window>`.
Jay
+1  A: 

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.

Heinzi