Content-related window size

I have two problems with the size of the window I have. The basic layout is like this

<Window MaxHeight="{DynamicResource {x:Static SystemParameters.VirtualScreenHeight}}"
        MaxWidth="{DynamicResource {x:Static SystemParameters.VirtualScreenWidth}}" 
        >
    <StackPanel>
        <DockPanel LastChildFill="False">
            <StackPanel DockPanel.Dock="Left"
                        Orientation="Horizontal">
                <!--Some buttons-->
            </StackPanel>
            <StackPanel DockPanel.Dock="Right"
                        Orientation="Horizontal">
                <!--Some buttons-->
            </StackPanel>
        </DockPanel>
        <ScrollViewer>
            <WrapPanel x:Name="Container">
            </WrapPanel>
        </ScrollViewer>
    </StackPanel>
</Window>

      

1) How can I make the Window not smaller horizontally than the DockPanel width?

2) How do I force the ScrollViewer to be constrained to the bounds of the window? It picks itself up to its content passing outside the window.
This used to work when I had

<Window><ScrollViewer/></Window>

      

but I really don't want the DockPanel inside the scroller. In its current form, it even makes the window crash its MaxHeight.

+1


source to share


2 answers


I would recommend using Grid with * Lenght instead of DockPanel and StackPanel.



+2


source


Just get rid of those StackPanel

s. Replace them with Grid

and you should be good. The layout logic StackPanel

is such that it will give the kids as much space in a specific direction (perpendicular to the orientation StackPanel

) as they ask. This is why you see problems with odd layout.



+1


source







All Articles