【问题标题】:align a text block to bottom of page将文本块与页面底部对齐
【发布时间】:2014-08-15 19:00:18
【问题描述】:

我正在尝试将我的 windows phone 应用程序的版本与页面的底部中心对齐。 它将其放置在视图中所有组件的底部(下方)。但不要到我的页面底部

<StackPanel>
    <TextBlock Text="Username:" Margin="12,0,0,0"/>
    <TextBox Text="{Binding UserName, Mode=TwoWay}" c4f:TextBinding.UpdateSourceOnChange="True" InputScope="EmailUserName" />
    <TextBlock Text="Password:" Margin="12,0,0,0"/>
    <PasswordBox Password="{Binding Password, Mode=TwoWay}" c4f:TextBinding.UpdateSourceOnChange="True" />
    <Button Content="Next" IsEnabled="{Binding CanMoveNext}" Command="{Binding LoginCommand}"/>
    <TextBlock Text="{Binding ConnectionError}"  TextWrapping="Wrap" FontSize="{StaticResource TitleSize}"></TextBlock>
    <TextBlock Text="{Binding VersionNumber}" Height="450" Padding="3" TextWrapping="Wrap" VerticalAlignment="Bottom" HorizontalAlignment="Center" FontSize="15"></TextBlock>
</StackPanel>

我希望它位于页面底部。

【问题讨论】:

    标签: xaml windows-phone


    【解决方案1】:

    您可以为此使用Grid

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0">
            ...
        </StackPanel>
        <TextBlock Grid.Row="1" Text="{Binding VersionNumber}" Padding="3" TextWrapping="Wrap" HorizontalAlignment="Center" FontSize="15"/>
    </Grid>
    

    这个Grid 包含两行。第二行取其内容所需的高度,第一行取剩余高度。可以在 visualstudiomagazine.com 上找到一篇很好的文章来解释这一点:Windows Phone Layout Using Grid

    【讨论】:

      【解决方案2】:

      不要为此使用StackPanel,因为StackPanel 只会为其内容使用尽可能多的空间(它不会填满页面)。

      Grid 在这里可能是一个不错的选择,DockPanel 也可以,尽管DockPanel 在 Windows Phone 上不可用。对于Grid,设置一些行,使底部元素位于底部行(您想要的位置)。它实际上可能是两行,一行用于“主要”内容,另一行用于页脚。

      对于DockPanel,将需要位于底部的元素设置为DockPanel.Dock="Bottom",其余(按顺序)设置为DockPanel.Dock="Top"。您可能需要将LastChildFill 属性设置为“False”以获得您想要的外观。

      【讨论】:

      • 我认为DockPanel 在 Windows Phone 上不可用。
      • @venerik 我不确定,当我回答时标签不同:)。网格可能是 OP 想要去这里的方式。
      • 非常感谢 Bradley 和 Venerik。我无法添加 DockPanel。用网格修复它。 :)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 2013-06-11
      • 2020-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多