主要是要设置HorizontalContentAlignment的值,而不是HorizontalAlignment
1 <ListBox x:Name="xxx"> 2 <ListBox.ItemContainerStyle> 3 <Style TargetType="ListBoxItem"> 4 <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 5 </Style> 6 </ListBox.ItemContainerStyle> 7 <ListBox.ItemTemplate> 8 <DataTemplate> 9 <StackPanel> 10 <Grid> 11 <TextBlock Text="www.tech-labs.net" HorizontalAlignment="Left"/> 12 <TextBlock Text="维思实验室" HorizontalAlignment="Right"/> 13 </Grid> 14 </StackPanel> 15 </DataTemplate> 16 </ListBox.ItemTemplate> 17 </ListBox>
本文来自飞絮飞啊飞的博客,原文地址:http://hi.baidu.com/%B7%C9%D0%F5%B7%C9%B0%A1%B7%C9/blog/item/a701fcfa3554fa8b