现在的位置: 首页 > 综合 > 正文

Silverlight 中 自定义的 ListBoxItem如何自适应ListBox的宽度

2012年02月08日 ⁄ 综合 ⁄ 共 503字 ⁄ 字号 评论关闭

主要是要设置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>

维思实验室

抱歉!评论已关闭.