问题
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:
After applying size to Browser Window (I want to get rid of that extra space surrounding the embedded browser):
回答1:
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.
回答2:
Change your DockPanel
to a StackPanel
, put it inside a Grid
, and set it's HorizontalAlignment
and VerticalAlignment
to Center
You might also need to play with the the Height
/Width
of the WebBrowser
to specify the initial size
<Grid>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Menu />
<WebBrowser Height="SomeValue" Width="SomeValue" />
</StackPanel>
</Grid>
回答3:
Can't you specify Width="Auto"
?
来源:https://stackoverflow.com/questions/7355999/way-to-make-wpf-dockpanel-auto-resize-based-on-its-childrens-size