A ListBoxItem that fills its parent

2019-07-18 11:44发布

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条回答
贪生不怕死
2楼-- · 2019-07-18 12:30

Can you try this?

<ListBox x:Name="yourListBox">
    <ListBox.ItemContainerStyle>                    
        <Style TargetType="ListBoxItem">                       
            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>                    
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>
查看更多
登录 后发表回答