对于databound items控件,我使用以下XAML来显示组列表,并使用标签和按钮首先添加新组:
<WrapPanel Orientation="Horizontal">
<Label Content="Groups" />
<Button x:Name="btnGroupAdd" Click="btnGroupAdd_Click" Content="+" />
<ItemsControl ItemsSource="{Binding}" x:Name="_groupList" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal">
</WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Padding="3" BorderThickness="1">
<WrapPanel>
<CheckBox x:Name="_groupEnabled" Click="GroupEnabled_Click" IsChecked="{Binding Path=Checked}">
<TextBlock x:Name="_groupName" Text="{Binding Path=Group.Name}" ></TextBlock>
</CheckBox>
<Button x:Name="_deleteGroup" FontStyle="Normal" Click="DeleteGroup_Click" />
</WrapPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
对于少量的组,所有内容都显示在一行上。
组+组1组2组3
当我添加更多组时,包含项目的“包装”面板将包装,但用于添加新组的初始标签和按钮位于其自己的行上,数据绑定组从下一行开始。
第1组第2组第3组第4组
组+组1组2组3
第4组第5组