Reputation: 8928
I have a TabControl
where each TabItem
shows a ListView
.
The list is the same for each tab, but it is sorted by different fields depending on the tab selected.
So, I don't want that each TabItem
contains a different ListView
:
<TabControl>
<TabItem>
<ListView/>
</TabItem>
<TabItem>
<ListView/>
</TabItem>
</TabControl>
How can I accomplish this?
Upvotes: 1
Views: 3120
Reputation: 15557
Quick and Easy. Let the code just the way it is now. Then have just one list on your ViewModel and you can have N diferent readonly properties (where N is the number of tabs) who will return the same list but sorted by your desired order.
The thing is:
I don't want that each TabItem contains a different ListView
But that's precisely what you're doing. Having a sorted-different list within each TabItem.
Example
View:
<TabControl>
<TabItem>
<ListView ItemsSource="{Binding SortedByX}" />
</TabItem>
<TabItem>
<ListView ItemsSource="{Binding SortedByY}" />
</TabItem>
<TabItem>
<ListView ItemsSource="{Binding SortedByZ}" />
</TabItem>
</TabControl>
ViewModel:
public List<The type of your list items> List { get; set; }
public List<The type of your list items> SortedByX
{
get
{
return List.Sort(iComparer);
}
}
// Or using LINQ
public List<The type of your list items> SortedByY
{
get
{
return List.OrderBy....
}
}
Upvotes: 2