代码之家  ›  专栏  ›  技术社区  ›  Roxy'Pro

如何在堆栈面板中正确对齐标签

  •  0
  • Roxy'Pro  · 技术社区  · 7 年前

    我正在努力实现这样的目标:

    enter image description here

    正如你所见,有一个标题“这就是我想要的”,与 另一个标签

    我写的代码:

          <Grid Width="345" Height="445" Background="White">
    
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
    
                <StackPanel Grid.Row="0" Orientation="Vertical" Margin="10">
                    <Label Content="How to align this to the left:" />
                    <StackPanel Grid.Row="1" Orientation="Horizontal" Background="#D9D9D9">
                        <Label Content="€" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        <Label Content="256,00" FontSize="38" FontWeight="Bold" />
                    </StackPanel>
                </StackPanel>
    
            </Grid>
    </Grid>
    

    enter image description here

    可能会注意到,标签没有左对齐,看起来有一些填充物或其他东西。。。

    而且标志也不在正确的位置,我试图实现这一点,就像在第一张图片上一样,但我尝试的所有不同类型的对齐方式(水平、居中)都不起作用。。

    谢谢大家 干杯

    1 回复  |  直到 7 年前
        1
  •  1
  •   mm8    7 年前

    设置 Padding Label 0 或使用 TextBlock . TextBlock比 标签 而且它没有违约 衬料 .

    你可以使用 Margin 属性将–sign-up稍微移动一点:

    <StackPanel Grid.Row="0" Orientation="Vertical" Margin="10">
        <TextBlock Text="How to align this to the left:" />
        <StackPanel Grid.Row="1" Orientation="Horizontal" Background="#D9D9D9">
            <TextBlock Text="€" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Bottom"
                                Margin="0 0 3 5"/>
            <TextBlock Text="256,00" FontSize="38" FontWeight="Bold" />
        </StackPanel>
    </StackPanel>