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

倾然丶 夕夏残阳落幕 提交于 2019-12-11 02:43:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!