/// <summary> /// Reorder the tabs and refresh collection sorting. /// </summary> /// <param name="reorder"></param> protected virtual void ReorderTabsCommandAction(TabReorder reorder) { ICollectionView view = CollectionViewSource.GetDefaultView(this.ItemCollection) as ICollectionView; int from = reorder.FromIndex; int to = reorder.ToIndex; var tabCollection = view.Cast<TabBase>().ToList();//Get the ordered collection of our tab control tabCollection[from].TabNumber = tabCollection[to].TabNumber; //Set the new index of our dragged tab if (to > from) { for (int i = from + 1; i <= to; i++) { tabCollection[i].TabNumber--; //When we increment the tab index, we need to decrement all other tabs. } } else if (from > to)//when we decrement the tab index { for (int i = to; i < from; i++) { tabCollection[i].TabNumber++;//When we decrement the tab index, we need to increment all other tabs. } } view.Refresh();//Refresh the view to force the sort description to do its work. }
/// <summary> /// Reorder the tabs and refresh collection sorting. /// </summary> /// <param name="reorder"></param> private void ReorderTabsCommandAction(TabReorder reorder) { ICollectionView view = CollectionViewSource.GetDefaultView(this.ItemCollection) as ICollectionView; int from = reorder.FromIndex; int to = reorder.ToIndex; var sourceCol = view.SourceCollection.Cast<ITab>().OrderBy(x => x.TabNumber).ToList();//Get the ordered source collection of our tab control sourceCol[from].TabNumber = sourceCol[to].TabNumber; //Set the new index of our dragged tab if (to > from) { for (int i = from + 1; i <= to; i++) { sourceCol[i].TabNumber--; //When we increment the tab index, we need to decrement all other tabs. } } else if (from > to)//when we decrement the tab index { for (int i = to; i < from; i++) { sourceCol[i].TabNumber++;//When we decrement the tab index, we need to increment all other tabs. } } view.Refresh();//Refresh the view to force the sort description to do its work. }
/// <summary> /// Tab自动排序 /// Tab可移动 /// </summary> /// <param name="reorder"></param> private void ExcuteReorderTabsCommand(TabReorder reorder) { ICollectionView view = CollectionViewSource.GetDefaultView(this.ItemCollection) as ICollectionView; int from = reorder.FromIndex; int to = reorder.ToIndex; var sourceCol = view.SourceCollection.Cast<ITab>().OrderBy(x => x.TabNumber).ToList(); sourceCol[from].TabNumber = sourceCol[to].TabNumber; if (to > from) { for (int i = from + 1; i <= to; i++) { sourceCol[i].TabNumber--; } } else if (from > to) { for (int i = to; i < from; i++) { sourceCol[i].TabNumber++; } } view.Refresh(); }