In SL, a default view is implicitly inserted between the source and the target, as long as it is bound to a collection that implements the IEnumerable interface, which stores information about the current item and supports
Sorting, grouping, filtering, navigating these features, here is a summary of Pagedcollectionview this view of the use of a few.
In fact, the view is automatically associated to the source collection rather than to the target object of the source, so changes to the views are automatically displayed on the target object.
Here are a few features to sum up:
Sort:
Mainly using the Sortdescriptions property to control View items, the basic idea is to select a property in the collection as a reference, and then set the way to sort, this setting will eventually be captured by a Sortdescription object.
Use an example to illustrate this problem:
First, create a data type, taking the photo class as an example:
public class Photo { public string Name { get; set; } public DateTime date { get; set; } public int Id { get; set; } }
Gets one of its data sets:
public class Photo
{
public string Name { get; set; }
public DateTime date { get; set; }
public int Id { get; set; }
}
Gets one of its data sets:
public class Photos
{
public List<Photo> GetList()
{
var list = new List<Photo>
{
new Photo{Name="Simens",Id=1,date=Convert.ToDateTime("2010/8/10")},
new Photo{Name="Sunshine",Id=2,date=Convert.ToDateTime("2010/8/13")},
new Photo{Name="TreeInforest",Id=3,date=Convert.ToDateTime("2010/8/15")},
new Photo{Name="WaterNaturl",Id=4,date=Convert.ToDateTime("2010/8/12")},
};
return list;
}
Here we take the DataGrid as an example, and for the whole process to be clearer, we set its Canusersortcolumns property to false and sort the data in the DataGrid by clicking the button
Ui:
<data:DataGrid AutoGenerateColumns="True" Height="131" HorizontalAlignment="Left" Margin="43,75,0,0" Name="dataGrid1"
CanUserSortColumns="False" VerticalAlignment="Top" Width="289" />
<Button Content="SortByName" Height="23" HorizontalAlignment="Left" Margin="52,221,0,0" Name="SortByName" VerticalAlignment="Top"
Width="75" Click="SortByName_Click" />
<Button Content="SortByDateTime" Height="23" HorizontalAlignment="Left" Margin="141,221,0,0" Name="SortByDateTime"
VerticalAlignment="Top" Width="75" Click="SortByDateTime_Click" />