我想列出一组对象,并让这些项目水平均匀分布。如果它不是一个数据绑定数组,我只需创建一个具有正确列数的网格并将每个项目分配给一列。问题是我不知道如何使用数据绑定列表控件来做到这一点。
作为一种廉价的替代方案,我使用堆栈面板作为 ItemsPanel 水平列出项目,用于 ItemsControl,如下所示:
<ItemsControl ItemsSource="{Binding Path=ValveSettings}" Grid.Row="0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Label Content="{Binding Path=Name}" Grid.Row="0" />
<ScrollBar Orientation="Vertical" Grid.Column="0" Grid.Row="1" Minimum="0" Maximum="100000" Value="{Binding Path=DelayInMicroseconds}" SmallChange="100" LargeChange="1000" />
<TextBox Text="{Binding Path=DelayInMicroseconds}" Grid.Row="2" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
有没有办法让它们均匀分布?