14

我有一个停靠面板,中间有一个标签,最右边有另一个按钮。

由于按钮的原因,当窗口最大化时,标签无法与中间对齐。

WPF:

<DockPanel Height="40" HorizontalAlignment="Stretch" Margin="-1,-2,0,0" Name="dockPanel1" VerticalAlignment="Stretch" Width="Auto" OpacityMask="{x:Null}">
            <Label FontSize="18" Content="Sales" FontWeight="Bold" FontFamily="Arial" Width="883" Height="42" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Foreground="White" DockPanel.Dock="Left" VerticalAlignment="Center" VerticalContentAlignment="Center"></Label>
            <Button FontSize="18" Height="47" Width="123" Name="btnStart" Foreground="White" BorderBrush="{x:Null}" FlowDirection="LeftToRight" HorizontalContentAlignment="Center" FontFamily="Arial Rounded MT" ClickMode="Press" DockPanel.Dock="Right" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="0" Content="Start" BorderThickness="0" Focusable="False">
        </DockPanel>
4

1 回答 1

25

使用 aGrid而不是 aDockPanel

网格允许将对象放置在彼此的顶部,因此您可以将标签放置在中间,将按钮放置在右侧

<Grid>
    <Label HorizontalAlignment="Center" VerticalAlignment="Center" />
    <Button HorizontalAlignment="Right" />
</Grid>

此外,如果您是 WPF 布局的新手,我建议您通读WPF 布局:快速可视化入门,以便了解可用的布局并选择最适合您的布局

于 2012-10-30T16:02:58.123 回答