[英]WPF Listbox style
I was following this tutorial: http://www.c-sharpcorner.com/uploadfile/dpatra/listbox-group-header-expand-and-collapse-in-wpf/ 我正在关注本教程: http : //www.c-sharpcorner.com/uploadfile/dpatra/listbox-group-header-expand-and-collapse-in-wpf/
And i tried to design my listbox with expanders. 我试图用扩展器设计列表框。
For some reason I'm getting something like this: 由于某种原因,我得到这样的东西:
Title (expander)
Tiltle(expander)
Data
Data
Data
I don't know what is causing the double-grouping and I need some help. 我不知道是什么原因导致双重分组,我需要一些帮助。
This is my code: 这是我的代码:
<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>
And in the view-model I have: 在视图模型中,我有:
InterfacesView = CollectionViewSource.GetDefaultView(Interfaces);
InterfacesView.GroupDescriptions.Add(new PropertyGroupDescription("Kind"));
InterfacesView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
The Kind is a property inside the "interface" clss 种类是“接口”内的属性
Change the code to this: 将代码更改为此:
InterfacesView view = CollectionViewSource.GetDefaultView(Interfaces);
view.GroupDescriptions.Add(new PropertyGroupDescription("Name"));
view.SortDescriptions.Add(new SortDescription("Name",ListSortDirection.Ascending));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.