我有这种情况:
<DockPanel>
<ListView DockPanel.Dock="Left" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="auto">
</ListView>
<Grid DockPanel.Dock="Left" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0">
<Button Content="1" Height="30" Width="30" />
</Grid>
<Grid DockPanel.Dock="Left" HorizontalAlignment="Left" VerticalAlignment="bottom" Margin="0,0,0,0">
<Button Content="2" Height="30" Width="30" />
</Grid>
</DockPanel>
我希望按钮1和按钮2垂直对齐。
在我的实际代码而不是Button 1中,我有多个带有标签的文本框,而按钮2是多个按钮,应该位于窗口的右下角,但是当窗口很小时,文本框会与按钮重叠。
我无法找到解决方案,所以我试图找到核心问题。
答案 0 :(得分:0)
我找到了一种方法来完成这项工作:
<DockPanel>
<ListView DockPanel.Dock="Left" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="auto">
</ListView>
<DockPanel DockPanel.Dock="Top">
<Grid DockPanel.Dock="Top" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0">
<Button Content="1" Height="30" Width="30" />
</Grid>
<Grid DockPanel.Dock="Bottom" HorizontalAlignment="Left" VerticalAlignment="bottom" Margin="0,0,0,0">
<Button Content="2" Height="30" Width="30" />
</Grid>
</DockPanel>
</DockPanel>
在网格周围放置一个额外的DockPanel,使网格停靠在顶部和底部。