Stick to the bottom of a StackPanel

前端 未结 3 1033
说谎
说谎 2020-12-18 20:41

In my window, there is a Grid that takes up 100% of the available vertical space. Inside that Grid is a StackPanel with another StackPanel and a Frame inside. I would like t

相关标签:
3条回答
  • 2020-12-18 21:07

    Looks more like a use case for DockPanel

    <DockPanel>
        <StackPanel>
            <!--//normal content-->
        </StackPanel>
        <Frame DockPanel.Dock="Bottom"/> <!--// should stick to the bottom-->
    </DockPanel>
    
    0 讨论(0)
  • 2020-12-18 21:25

    A StackPanel is not the correct Panel to use for your requirements as they do not provide the same layout and resizing capabilities as a Grid. Therefore, simply replace it with a Grid, give the majority of the space to the inner StackPanel and then the Frame will stick to the bottom.

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />   
        </Grid.RowDefinitions>
        <StackPanel>
           //normal content
         </StackPanel>
         <Frame Grid.Row="1" />
    </Grid>
    

    You can find out more about the different WPF Panels in the Panels Overview page on MSDN.

    0 讨论(0)
  • 2020-12-18 21:32

    According to MSDN docs about StackPanel

    A StackPanel Arranges child elements into a single line that can be oriented horizontally or vertically.

    So in your case, StackPanel is not the right control to use. If you want your control to be fixed at a particular position, you can use DockPanel and place your control inside it.

    <DockPanel>
            <Frame DockPanel.Dock="Bottom"/>
    </DockPanel>
    
    0 讨论(0)
提交回复
热议问题