【问题标题】:Align TextBlock inside a ListBoxItem在 ListBoxItem 内对齐 TextBlock
【发布时间】:2011-04-11 15:10:19
【问题描述】:

我正在开发一个 Windows Phone 7 应用程序。

我想将 ListBoxItem 内的文本块垂直居中。这是我的 XAML 代码:

<ListBoxItem x:Name="SingleGameItem" Height="79" Margin="10,5">
    <TextBlock HorizontalAlignment="Center" Height="31" Margin="5" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Center" Width="431" TextAlignment="Center"/>
</ListBoxItem>

我该怎么做?

【问题讨论】:

  • 使用已发布的 XAML 时会发生什么?
  • 您是否尝试在 ListBox 或 ListBoxItem 本身上将 VerticalContentAlignment 设置为 Center
  • TextBlock 在 ListBoxItem 顶部垂直对齐。
  • 我找到了问题(我的问题)。对不起。你可以在我的回答中看到。我已将 VerticalAlignment="Center" 添加到 ListBoxItem。

标签: windows-phone-7 textblock listboxitem text-alignment


【解决方案1】:

解决办法是:

<ListBox x:Name="Options" Margin="12,8,8,8" Grid.Row="1">
    <ListBoxItem x:Name="SingleGameItem" Height="79" Margin="10,5" VerticalAlignment="Center">
        <TextBlock HorizontalAlignment="Center" Height="31" Margin="5" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Center" Width="431" TextAlignment="Center"/>
    </ListBoxItem>
</ListBox>

对不起。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-20
    • 2011-09-07
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 2014-10-10
    • 2010-12-02
    相关资源
    最近更新 更多