WPF ListBox - 在GroupStyle中使用ItemTemplate

时间:2013-03-17 14:18:02

标签: c# wpf listbox grouping itemtemplate

我正在尝试制作分组列表框。首先我做了一个ItemTemplate。现在我正在尝试对数据进行分组,但我不知道如何使用该ItemTemplate。有人可以帮我一点吗?

我当前的列表框xaml

    <ListBox x:Name="kontakty" ItemsSource="{Binding kontakt}">
        <ListBox.GroupStyle>
            <GroupStyle HeaderStringFormat="Group">
                <GroupStyle.ContainerStyle>
                    <Style TargetType="{x:Type GroupItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type GroupItem}">
                                    <StackPanel>
                                        <TextBlock Text="{Binding Path=Name}" Foreground="Red"/>
                                        <ComboBox ItemsSource="{Binding Path=Items}" DisplayMemberPath="Name"/>
                                    </StackPanel>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </GroupStyle.ContainerStyle>
            </GroupStyle>
        </ListBox.GroupStyle>
        <ListBox.ItemTemplate>
            //...............//
        </ListBox.ItemTemplate>
    </ListBox>

1 个答案:

答案 0 :(得分:1)

解决方案是将ItemConmplate与ItemSmplate一起添加到GroupStyle。

相关问题