我有一个全屏对话框,想要使画布居中。例如,它似乎适用于具有垂直/水平对齐标签的网格,但是当我尝试这个时,左上角会居中而不是画布的中间:
<Window
Title=""
Topmost="True" WindowStyle="None" WindowState="Maximized"
>
<Grid>
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
<Canvas>
<Border Margin="20"
Background="White"
BorderBrush="Black"
BorderThickness="2"
Padding="20" >
<DockPanel Margin="10">
<StackPanel DockPanel.Dock="Top" Margin="0 0 0 50"
Orientation="Vertical">
<Label FontSize="32" Content="Hello"></Label>
</StackPanel>
<StackPanel HorizontalAlignment="Right"
DockPanel.Dock="Bottom"
Orientation="Horizontal">
<Label FontSize="32" Content="Hello"></Label>
</StackPanel>
</DockPanel>
</Border>
</Canvas>
</Grid>