问题
I'm developing a Windows Phone app.
I have the following XAML:
<!--ContentPanel -->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="SinglesGameList" Margin="0">
<ListBoxItem Margin="10,10,10,5" Height="67" HorizontalAlignment="Center" VerticalAlignment="Center" Width="444">
<TextBlock Text="XXX"/>
</ListBoxItem>
</ListBox>
</Grid>
Instead of setting ListBoxItem Width="444" I'm wondering it there is another way to set it that fills its parent.
Any advice?
回答1:
Can you try this?
<ListBox x:Name="yourListBox">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
来源:https://stackoverflow.com/questions/5639466/a-listboxitem-that-fills-its-parent