【发布时间】:2014-04-25 14:25:37
【问题描述】:
我正在关注本教程: http://www.c-sharpcorner.com/uploadfile/dpatra/listbox-group-header-expand-and-collapse-in-wpf/
我尝试用扩展器设计我的列表框。
由于某种原因,我得到了这样的东西:
Title (expander)
Tiltle(expander)
Data
Data
Data
我不知道是什么导致了双重分组,我需要一些帮助。
这是我的代码:
<ListBox Grid.ColumnSpan="3" Grid.Row="3"
Name="lbInterfaces" Background="Transparent" ItemsSource="{Binding InterfacesView }" ItemTemplate="{StaticResource InterfacesDataTemplate}" BorderBrush="Transparent">
<ListBox.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource ContainerStyle}"/>
</ListBox.GroupStyle>
</ListBox>
<Style x:Key="ContainerStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander Header="{Binding Name}" IsExpanded="False">
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="InterfacesDataTemplate"
DataType="ca:Interface">
<Grid>
<TextBlock Text="{Binding Path=Name}" MouseLeftButtonDown="interface_mouseDown"/>
</Grid>
</DataTemplate>
在我的视图模型中:
InterfacesView = CollectionViewSource.GetDefaultView(Interfaces);
InterfacesView.GroupDescriptions.Add(new PropertyGroupDescription("Kind"));
InterfacesView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
Kind 是“接口”类中的一个属性
【问题讨论】:
标签: c# wpf listbox expandablelistview expander