列表父控件ItemsContro

ItemsControl是用来表示一些条目集合的控件,它的成员是一些其它控件的集合

像是ListBoxListViewComboBox都是继承于ItemsControl

ItemsControl可以很好的控制列表的 形状、方向、可以定义包裹的组件的容器

ItemsControl的最重要的3个属性
  1. ItemsSource:主要用来绑定到数据源,以将数据填充到ItemsControl中
  2. ItemsPanel:设置包裹items的父组件, 如:是以StackPanel的形式,还是以Grid的形式来显示ItemsControl包含的所有元素。
  3. ItemTemplate:其类型为DataTemplate,主要定义数据模板用
例子:
<ItemsControl ItemsSource="{Binding Model.Playlist.tags}">
    <!---定义父容器-->
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <!--定义数据模板-->
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Button Style="{DynamicResource DefaultButtonStyle}"  Content="{Binding}" Margin="0 2 0 2" FontSize="12" Foreground="#517eaf"/>
                <Label Content="/" FontSize="12" Foreground="#5a5a5a"/>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>