PRISM RegionManager - TabControl Tabs order

I have a TabControl region, where i am adding new tabs throw RequestNavigate method. Everything's working fine. But problem is, that new tabs are placed on the last position to the right. But i need to add them right next to active tab. So when i have 10 open tabs, but active is first tab - i want to add new opened tab to second place and move other tabs to right. Thx a lot

Upvotes: 3

Views: 1815

Answers (1)

Ok, thanks to Sam's solution https://stackoverflow.com/a/4285764/1027262 I figured out that there is a SortComparison property of IRegion class that is responsible for sorting views inside region.

So my View classes implements ISortableView interface, that contains

public int SortIndex {get;set;}

This SortIndex is then used for sorting Views in region. SortComparison method looks like this:

private static int CompareViews(object x, object y) 
{ 
    return ((ISortableView)x).SortIndex.CompareTo(((ISortableView)y).SortIndex); 
} 

this._regionManager.Regions["MyRegion"].SortComparison = CompareViews; 

Then I had to make service class, that is responsible for managing Views index. Index of parent view i am sending throw OnNavigatedFrom method of INavigationAware interface. But be aware of setting SortIndex in OnNavigatedTo method. This method is called AFTER region sort its views.

Upvotes: 2

Related Questions