Wpf 对齐窗口顶部和底部的内容
我不知道如何在WPF中使一些内容与屏幕顶部对齐,而另一些与屏幕底部对齐。基本上,我想在窗口的顶部放置两行内容,在底部放置两行内容。注意,我是WPF的初学者 我就是这样尝试的:Wpf 对齐窗口顶部和底部的内容,wpf,xaml,Wpf,Xaml,我不知道如何在WPF中使一些内容与屏幕顶部对齐,而另一些与屏幕底部对齐。基本上,我想在窗口的顶部放置两行内容,在底部放置两行内容。注意,我是WPF的初学者 我就是这样尝试的: <StackPanel> <StackPanel VerticalAlignment="Top"> <!-- some code here --> </StackPanel> <StackPanel Vertical
<StackPanel>
<StackPanel VerticalAlignment="Top">
<!-- some code here -->
</StackPanel>
<StackPanel VerticalAlignment="Bottom">
<!-- some code here -->
</StackPanel>
</StackPanel>
但这不起作用。解决方案是什么?类似的方法可能会奏效。我还没有在VS中运行它,所以它可能有点不正常
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
// some code here
</StackPanel>
<StackPanel Grid.Row="1">
//EMpty
</StackPanel>
<StackPanel Grid.Row="2">
// some code here
</StackPanel>
</Grid>
//这里有一些代码
//空的
//这里有一些代码
表示占用所有剩余空间
表示只需展开以适合包含的元素您可以使用。使用“附着”特性可以设置子图元的位置。坞面板中的最后一个元素将占用剩余空间。如果不需要,可以将其属性设置为false
<DockPanel>
<StackPanel DockPanel.Dock="Top">
<Button Content="Top 1" />
<Button Content="Top 2" />
</StackPanel>
<StackPanel DockPanel.Dock="Bottom">
<Button Content="Bottom 1" />
<Button Content="Bottom 2" />
</StackPanel>
<Grid>
<TextBlock Text="Center"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</Grid>
</DockPanel>
结果是这样的
对我来说不是。每个StackPanel中都有一个网格元素,这可能是一个问题吗?请使用带有适当行定义的
网格,而不是StackPanel
。
<DockPanel>
<Button DockPanel.Dock="Top" Content="Top 1" />
<Button DockPanel.Dock="Top" Content="Top 2" />
<Button DockPanel.Dock="Bottom" Content="Bottom 1" />
<Button DockPanel.Dock="Bottom" Content="Bottom 2" />
<TextBlock Text="Center"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</DockPanel>