xaml – ListView ItemTemplate 100%width

使用DataTemplate时,如何使每个ListView项目的内容扩展为100%的宽度?

我已经尝试过ListView中的Horizo​​ntalContentAlignment =“Stretch”和DataTemplate中的Horizo​​ntalAlignment =“Stretch”,但似乎没有任何效果,内容仍然对齐在左边。

我有这样的东西:

<ListView x:Name="questionsView" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" HorizontalContentAlignment="Stretch">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Border Background="BlueViolet" HorizontalAlignment="Stretch">
                <Grid HorizontalAlignment="Stretch">
                    <TextBlock Text="{Binding}" />
                    <TextBlock HorizontalAlignment="Right">16 minutes ago</TextBlock>
                </Grid>
            </Border>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

我想在ListView和ItemTemplate之间还有一层。

我知道了。使用Horizo​​ntalContentAlignment设置器设置ListView.ItemContainerStyle就成了窍门。即:

<ListView x:Name="questionsView" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Border Background="BlueViolet">
                <Grid HorizontalAlignment="Stretch" Margin="0">
                    <TextBlock Text="{Binding}" />
                    <TextBlock HorizontalAlignment="Right">16 minutes ago</TextBlock>
                </Grid>
            </Border>
        </DataTemplate>
    </ListView.ItemTemplate>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </ListView.ItemContainerStyle>
</ListView>
http://stackoverflow.com/questions/18626696/listview-itemtemplate-100-width

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:xaml – ListView ItemTemplate 100%width