[英]auto-fit Grid Columns in UWP XAML
I'm using GridView to create a grid of items, and im trying to make the columns fill to expand the remaining space.我正在使用 GridView 创建项目网格,并且我试图使列填充以扩展剩余空间。 Similar to how
auto-fit
behaves in CSS.类似于 CSS 中
auto-fit
行为。 See example.见例子。 .
.
Here I've set the MaxWidth of the GridView's children to 350px, and then when the window is not an even multiple of 350px + padding, I would like each column to expand to fill the remaining space.在这里,我将 GridView 的子项的 MaxWidth 设置为 350px,然后当 window 不是 350px + padding 的偶数倍时,我希望每列扩展以填充剩余空间。
Is this possible with UWP/XAML?这对 UWP/XAML 可行吗?
If you want to achieve the auto-fit effect, you can try to use UniformGrid Control from Windows Community Toolkit.如果想实现自动拟合效果,可以尝试使用 Windows Community Toolkit 中的UniformGrid Control 。 It is a responsive layout control which arranges items in a evenly-spaced set of rows or columns to fill the total available display space.
它是一种响应式布局控件,可将项目排列在一组均匀分布的行或列中,以填充可用的总显示空间。 First, you need to add Microsoft.Toolkit.Uwp.UI.Controls nuget package and then use it as GridView's ItemsPanel .
首先,您需要添加Microsoft.Toolkit.Uwp.UI.Controls nuget package ,然后将其用作 GridView 的ItemsPanel 。 For example:
例如:
.xaml: .xaml:
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<controls:UniformGrid Columns="3" Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.