我有以下XAML,它在一行中水平显示四个按钮。
如何使其每行显示三个按钮,并根据需要显示多少行?
<ItemsControl ItemsSource="{Binding DataButtons}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="20"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Width="100" Height="100"
Content="{Binding ButtonName}"
Command="{Binding ButtonCommand}"
CommandParameter="{Binding FilePath}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
答案 0 :(得分:0)
听起来像您想使用的是UniformGrid
之类的“ ASh”,它可以让您将Columns
设置为3,并自动缩放Rows
的数量根据{{1}}中有多少项。我发现此方法比手动堆叠WrapPanels容易得多。