A ListBoxItem that fills its parent

╄→гoц情女王★ 提交于 2020-01-04 05:51:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!