代码之家  ›  专栏  ›  技术社区  ›  Adam Rackis

Silverlight float内容右

  •  7
  • Adam Rackis  · 技术社区  · 15 年前

    我试着得到一个带有文本的水平堆叠面板,然后一个按钮一直卡在右手边。我试过这个:

                    <StackPanel Orientation="Horizontal">
                        <TextBlock VerticalAlignment="Center" FontSize="14" Margin="5,0,0,0">Ahoy!</TextBlock>
                        <Button HorizontalAlignment="Right" Width="25" Height="25" Style="{StaticResource buttonGlassOrb}" Background="Red" />
                    </StackPanel>
    

    这似乎不起作用。显然,向文本块添加边距将起作用,如下所示:

                    <StackPanel Orientation="Horizontal">
                        <TextBlock VerticalAlignment="Center" FontSize="14" Margin="5,0,120,0">Ahoy!</TextBlock>
                        <Button HorizontalAlignment="Right" Width="25" Height="25" Style="{StaticResource buttonGlassOrb}" Background="Red" />
                    </StackPanel>
    

    但这有各种各样的原因。有没有更自然的方法可以做到这一点?

    3 回复  |  直到 15 年前
        1
  •  8
  •   Reed Copsey    15 年前

    就我个人而言,我会使用一个网格来代替StackPanel。只需添加两列,一列设置为大小“*”,一列设置为“自动”,然后将文本块放在第一列,按钮放在第二列:

        2
  •  3
  •   John Bowen    15 年前

    改用DockPanel:

    <DockPanel>
        <TextBlock VerticalAlignment="Center" FontSize="14" Margin="5,0,0,0">Ahoy!</TextBlock>
        <Button DockPanel.Dock="Right" Width="25" Height="25" Style="{StaticResource buttonGlassOrb}" Background="Red" />
    </DockPanel>
    

        3
  •  2
  •   vc 74    15 年前

    StackPanels适用于简单的场景,只要您想完全控制布局,就使用Grid