Way to make WPF DockPanel auto-resize based on its children's size?

dxue picture dxue · Sep 9, 2011 · Viewed 10k times · Source

Right now I have a DockPanel that contains a toolbar and BrowserWindow. When I re-size the BrowserWindow to fit content, I want that change to propagate up into the DockPanel and re-size automatically. Is there a setting for this?

So the layout of my app is essentially:

-Browser Control Class

--DockPanel

----Toolbar (docked to Top)

----Browser Window Class

------Grid

--------Menu

--------Embedded Browser

Basically I want the size that I set on my Browser Window Class to automatically re-size the DockPanel.

Before applying size to Browser Window:

http://imgur.com/qlgwA

After applying size to Browser Window (I want to get rid of that extra space surrounding the embedded browser):

http://imgur.com/YFJrh

Answer

klm_ picture klm_ · Sep 9, 2011

DockPanel has a LastChildFill property that you can use. Try to play with it a little. Remember that BrowserWindow needs to be the last child in DockPanel.

I think you will also have to change something in your Grid. By LastChildFill property should be set. You are on right track at least.