[ACCEPTED]-How to make items in a DockPanel expand to fit all available space in WPF?-dockpanel

Accepted answer
Score: 11

Use a DockPanel instead. StackPanel explicitly 12 doesn't care about visible space, whereas 11 DockPanel does all of it's size calculation 10 based on available space.


In addition, in 9 my experience, putting the body of the window 8 into a View, and only having the View in 7 the Window makes for a better Auto Size 6 experience.

For some reason putting all 5 of the children directly into the Window 4 seems to not auto size very well.

Update 2:

I would 3 remove the explicit DockPanel.Dock attribute 2 from the element that you want to stretch 1 (fill) the unused space.

Score: 9

This should do it - I set it up so that 4 the TreeView and the ListView shared the 3 main view 50/50; if you don't want that, set 2 it to 'Auto' and '*' or something. Use "LastChildFill" to 1 your advantage!

<Window x:Class="Clippy.MainWindow"
        Title="MainWindow" Height="400" Width="600" MinHeight="400" MinWidth="600" Loaded="Window_Loaded" SizeChanged="Window_SizeChanged">

    <DockPanel LastChildFill="True">
        <Menu Width="Auto" DockPanel.Dock="Top" />
        <ToolBar Width="Auto" DockPanel.Dock="Top" />
        <StatusBar DockPanel.Dock="Bottom" />

                <RowDefinition Height="0.5*" />
                <RowDefinition Height="0.5*" />

            <TreeView Name="categoryTreeView" Grid.Row="0" />
            <ListView Name="clipListView" Grid.Row="1" />

Score: 0

Set width and height properties to "auto"


More Related questions