WPF and Silverlight Learning notes (25): Using CollectionView to implement sorting, filtering, grouping of bound data
In the 23rd section, we use CollectionView to implement the navigation of bound data, in addition to navigation function, but also through CollectionView to the data similar to DataView sorting, filtering and other functions.
One, the data sorting:
Use the data source in section 24th to query all product information:
1: <window x:class= "Wpf_24.collectionviewsortdata"
2:xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation& quot;
3:xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
4:xmlns:lib= "Clr-namespace:wpf_24_library;assembly=wpf_24_library"
5:title= "Collectionviewsortdata" height= "width=" >
6: <Window.Resources>
7: <objectdataprovider x:key= "myDataSource"
8:objecttype= "{x:type Lib:datacontrol}"
9:methodname= "Getallproductinfo"/>
: </Window.Resources>
One: <grid margin= "5" >
<Grid.RowDefinitions>
<rowdefinition/>
<rowdefinition height= "/>"
: </Grid.RowDefinitions>
: <listbox grid.row= "0"
17:datacontext= "{StaticResource myDataSource}"
18:itemssource= "{Binding}" >
: <ListBox.ItemTemplate>
<DataTemplate>
<WrapPanel>
<textblock text= "{Binding Path=productid}" width= "-"/>
<textblock text= "{Binding path=productname}" width= "-"/>
<textblock text= "{Binding path=unitprice}" "Width="/>
: </WrapPanel>
: </DataTemplate>
: </ListBox.ItemTemplate>
: </ListBox>
: <wrappanel grid.row= "1" verticalalignment= "center" horizontalalignment= "Center" >
<textblock text= "First sort:" verticalalignment= "Center"/>
: <combobox selectedindex= "0" width= "x:name=" Cmbcolumna ">
<ComboBox.Items>
: <comboboxitem tag= "ProductID" > Product No. </ComboBoxItem>
: <comboboxitem tag= "ProductName" > Product name </ComboBoxItem>
£ <comboboxitem tag= "UnitPrice" > Product price </ComboBoxItem>
-</ComboBox.Items>
Panax Notoginseng: </ComboBox>
<textblock text= "Second order:" verticalalignment= "Center"/>
: <combobox selectedindex= "0" width= "x:name=" CMBCOLUMNB ">
<ComboBox.Items>
: <comboboxitem tag= "ProductID" > Product No. </ComboBoxItem>
: <comboboxitem tag= "ProductName" > Product name </ComboBoxItem>
<comboboxitem tag= "UnitPrice" > Product price </ComboBoxItem>
: </ComboBox.Items>
: </ComboBox>
<button content= "Sort" margin= "10,0,0,0" click= "Button_Click"/>
: </WrapPanel>
</Grid>
: </Window>