views:

23

answers:

1

I'm running into a dilemma. When I make the ScrollViewer the main content object of my window, scrolling behaves exactly like I want it to. You resize to make it smaller than the content and the window and scroll bars appear. The problem comes in when I want the to menu to be static and the rest of content to be scrollable. I want the scroll bars to behave the same way as a browser window does, meaning when you resize it, the scroll bars appear based on the size of the content. When you expand the window, the content takes up the entire real estate of the window. Is that possible in WPF?

Help would be GREATLY appreciated.

A: 

Make a DockPanel the main content object of your window. Insert your top menu as the first child (with DockPanel.Dock="Top") and the ScrollViewer (containing the rest of the window's content) as the second child. In a DockPanel, the last child takes up all the remaining space, which should be what you want.

<Window ...>
    <DockPanel>
        <MyMenu DockPanel.Dock="Top" ... />
        <ScrollViewer>
            ....
        </ScrollViewer>
    </DockPanel>
</Window>
Heinzi
Amazing, thank you! I was using a StackPanel, and that didn't work at all!
Greg R
@Greg: You're welcome; glad to hear it worked. The problem with `StackPanel` is that it does not automatically stretch to the available space. Instead, it only uses the space "required" by the inner elements.
Heinzi
Ahh, that makes sense, thanks a lot!
Greg R