自定义的 ListBoxItem 自适应ListBox的宽度
主要是要设置HorizontalContentAlignment的值,而不是HorizontalAlignment
<ListBox x:Name="xxx">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Grid>
<TextBlock Text="www.tech-labs.net" HorizontalAlignment="Left"/>
<TextBlock Text="维思实验室" HorizontalAlignment="Right"/>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Grid>
<TextBlock Text="www.tech-labs.net" HorizontalAlignment="Left"/>
<TextBlock Text="维思实验室" HorizontalAlignment="Right"/>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
慎于行,敏于思!GGGGGG