Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

wpf - Stick to the bottom of a StackPanel

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 to have that Frame stick to the bottom of the parent StackPanel.

<StackPanel>
    <StackPanel>
       //normal content
     </StackPanel>
     <Frame /> // should stick to the bottom
</StackPanel>

So that, for example, when the user resizes the Window and the Grid gains height, the Frame inside sticks to the bottom.

I have tried various things, using VerticalAlign="Stretch" or a DockPanel and assigning the Frame a DockPanel.Dock="Bottom", but to no success. I'd be thankful for a hint or two. I don't need the StackPanel to be a StackPanel, it can also be a DockPanel.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...