【问题标题】:UWP XAML: Can't bring GridView item to stretch to full widthUWP XAML:无法将 GridView 项目拉伸到全宽
【发布时间】:2018-09-07 16:05:54
【问题描述】:

我所看到的关于这个问题的所有解释都不适用于我的情况,其中大多数甚至不适用于 UWP XAML。

如何让 GridView Grid Items Container 伸展到全宽? (请参阅我在 XAML 中的“Stretch this...”评论。)

PS:将 GridView 更改为 ListView 不会改变任何内容。

XAML:

<Grid>
    <GridView x:Name="barGrid" ItemsSource="{x:Bind projects}" Margin="10" HorizontalAlignment="Stretch" 
              HorizontalContentAlignment="Stretch" Background="Pink">
        <GridView.ItemTemplate>
            <DataTemplate x:Name="DoubleBars" x:DataType="local:Project">
                <!-- **Stretch this to the max container width!** -->
                <Grid HorizontalAlignment="Stretch" Background="Orange">
                    ...
                </Grid>
            </DataTemplate>
        </GridView.ItemTemplate>

        <GridView.ItemsPanel>
            <ItemsPanelTemplate>
                <ItemsWrapGrid Orientation="Vertical" HorizontalAlignment="Left"/>
            </ItemsPanelTemplate>
        </GridView.ItemsPanel>

    </GridView>
</Grid>

【问题讨论】:

    标签: uwp-xaml


    【解决方案1】:

    秘诀在于 ListViewItem 的样式定义

    <ListView x:Name="barGrid" 
          ItemsSource="{x:Bind projects}"
          Margin="10" 
          HorizontalAlignment="Stretch"
          HorizontalContentAlignment="Stretch" 
          Background="Pink">
    <ListView.Resources>
        <Style Target="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </ListView.Resources>
    <ListView.ItemTemplate>
        <DataTemplate x:Name="DoubleBars" x:DataType="local:Project">
            <!-- **Stretch this to the max container width!** -->
            <Grid HorizontalAlignment="Stretch" Background="Orange">
                ...
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      • 2016-05-24
      • 2015-11-27
      • 1970-01-01
      • 2019-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多