After you change the datasource of the itemscontrol of WPF, the previous icollectionview will disappear, so the data sorting, classification, and handsome selection function will disappear, because the data is kept in the icollectionview. However, The ListBox or listview of WPF can select the object selected in the previous datasource.
The followingProgramAfter you rebind the data, if the "Save status" is selected, the listview retains the status of the previous data binding. At the same time, the last equivalent Project (if any) will be selected. This is done through the equals method of the data object. However, this function has mentioned that even if you do not specifically copy icollectionview, The ListBox/listview of WPF will do the same. (Of course, the program is rebound.CodeA project that is the same as the selected project is automatically generated)
The key method is:
Static IcollectionviewCopy (IcollectionviewView,ObjectOBJ)
{
VaRRET= Collectionviewsource.Getdefaview view (OBJ );
Foreach(VaRGroupInView.Groupdescriptions)
RET.Groupdescriptions.Add (group );
Foreach(VaRSortInView.Sortdescriptions)
RET.Sortdescriptions.Add (SORT );
RET.Filter=View.Filter;
RET.Movecurrentto (View.Currentitem );
ReturnRET;
}
Source Code download
note: this is an archive of Microsoft SkyDrive. Please download it directly in a browser. Some download tools may not be available for download.
source code environment: Microsoft Visual C #2010 express