wp7中的列表框对齐问题

时间:2012-08-07 06:03:29

标签: windows-phone-7 xaml expression-blend

我有列表框,我在其中放置了一些标签。

 <ListBox x:Name="lstContacts">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                            <HyperlinkButton Height="30" Margin="-10,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Content="{Binding PhoneType, Converter={StaticResource CntctConverter}}" Style="{StaticResource HyperlinkButtonStyle}"/>
                                            <TextBlock Height="30" HorizontalAlignment="Left" Text="{Binding PhoneNumber}" Width="250" Foreground="{StaticResource TitleBrush}" Tap="lblMobile_Tap" VerticalAlignment="Top"/>
                                            <TextBlock Height="30" Text="{Binding CallRate}" HorizontalAlignment="Right" Foreground="{StaticResource TitleBrush}" Margin="0,-30,0,0" VerticalAlignment="Top"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>

我的最后一个标签应该是极右派,因为我的水平对齐方式是正确的。 但它的中心。请参阅快照

enter image description here

请建议我在哪里犯错误

2 个答案:

答案 0 :(得分:0)

这与ListBox的默认Horizo​​ntalAlignment有关。它默认为Left。您需要将其更改为Stretch。

<ListBox>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

答案 1 :(得分:0)

由于第一个TextBox宽度值,您的StackPanel宽度为250,因此看起来第二个TextBlock正确地位于右侧。

您需要通过向其添加Width值来增加stackpanel的宽度。

相关问题