是否可以在xaml中制作GridView的内容拉伸,以便在更改GridView的宽度时,项目处理拉伸?我尝试使用HorizontalContentAlignment但它不起作用。
MainPage.xaml中:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<GridView x:Name="GridViewItemList" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch" ItemContainerTransitions="{x:Null}" Margin="0,50,0,0" SizeChanged="GridViewItemList_SizeChanged">
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridViewItem Content="Item" Width="100" Height="100" HorizontalContentAlignment="Center" Background="#FF2D7496" Foreground="White" FontSize="36"/>
<GridView.Style>
<Style TargetType="GridView">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Margin" Value="5"/>
</Style>
</GridView.Style>
</GridView>
</Grid>
我想,随着GridView的宽度发生变化,这些项目会在GridView的整个宽度上展开。
感谢您的帮助。
答案 0 :(得分:1)
您应该查看属于AdaptiveGridView
control的UWP Community Toolkit。在这方面,这种控制非常智能,并且可以根据需要自动拉伸控件,使得行被平均填充,并且两侧都没有剩余空间。