2012-08-07 71 views
0

我有列表框,我正在放置一些标签。wp7列表框对齐问题

<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

请建议我在哪里造成任何错误

回答

0

你的StackPanel宽度是250,因为所述第一文本框宽度值的,所以看起来所述第二TextBlock的正确positoned到右侧。

您需要通过向其添加宽度值来增加堆叠面板的宽度。

+0

爵士Jon I Am谈论Horizo​​natal对齐我的TextBlock,我已经设置它所以它不会看到谁被留下,它将被正确地对齐页面宽度将不重要:) – 2012-08-09 04:37:30

+0

您的StackPanel根据内容调整大小,第二个TextBox右对齐到堆叠面板而不是页面。尝试添加 Jon 2012-08-09 05:53:27

0

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

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

什么也没有做到这一点肖恩:( – 2012-08-07 07:37:43

+0

请确保你也设置了StackPanel的Horizo​​ntalAlignment,如果你使用它,它也默认为Left – 2012-08-07 15:22:08