[Wpf]在C#中添加 collectionViewSource

Products = new ObservableCollection<Product>(products);

ProductOptions = new ObservableCollection<ProductOption>(options);
 
ProductsView = CollectionViewSource.GetDefaultView(Products);
    ProductsView.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
    ProductsView.SortDescriptions.Add(
        new SortDescription("Name", ListSortDirection.Ascending));
 
ProductOptionsView = CollectionViewSource.GetDefaultView(ProductOptions);
    ProductOptionsView.SortDescriptions.Add(
        new SortDescription("Option", ListSortDirection.Ascending));
 

<ListBox Grid.Row="1" ItemsSource="{Binding Products}"
DisplayMemberPath="Name">
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Foreground="DarkGreen" Text="{Binding Name}"
FontStyle="Italic"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListBox.GroupStyle>

[Wpf]在C#中添加 collectionViewSource

上一篇:Lesson 01 Windows程序运行原理及程序编写(SDK)


下一篇:C# Socket-TCP异步编程原理详解附源码