WPF列表框分组

3
我需要在列表框中像下面这样显示。场景是它将有多个分组,然后是水平对齐的项目。
    GroupA
      GroupA Description
    GroupB
      GroupB Description
    Items Available
     ItemA ItemB ITemC
1个回答

1
您可以尝试使用这段代码。
<Style x:Key="ContainerStyle" TargetType="{x:Type GroupItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Expander Header="{Binding ....}" IsExpanded="True">
                            <ItemsPresenter />
                        </Expander>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
</Style>


<ListBox x:Name="lbPersonList" Margin="19,17,162,25" AlternationCount="2">
            <ListBox.GroupStyle>
                <GroupStyle ContainerStyle="{StaticResource ContainerStyle}"/>
            </ListBox.GroupStyle>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding ...}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
</ListBox>

注意:请在您的代码中调整绑定。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接