1
我有一组数据项,应该在一行中的页面上表示。ItemsControl中的拉伸按钮
<ItemsControl ItemsSource="{x:Bind ViewModel.PresetsSecondLine, Mode=OneWay}"
Visibility="{x:Bind ViewModel.IsExpanded, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Margin="0 5">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal"
HorizontalChildrenAlignment="Stretch"
MaximumRowsOrColumns="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="entities:Preset">
<controls:PresetButtonControl Preset="{x:Bind}"
VerticalAlignment="Stretch"
Width="290"
Margin="5"
Style="{StaticResource DashboardButtonStyle}"
HorizontalAlignment="Stretch" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
该集合可能包含从零到四个项目显示在一行中。如果有4个项目,它们应该填满整行。当有少于4项就应该按比例显示:
,我发现这样的问题的解决与UniformGrid
,可惜UniformGrid
不是不再UWP支持。
您可以使用与此相同的概念显示在此处(http://stackoverflow.com/questions/22871767/how-can-i-achieve-this-mix-of-stackpanel-and-uniformgrid-behavior)项目容器,这是提供我正确理解您的预期结果。 –