I have an UWP application.
One view with a pivot control.
One associated ViewModel.
One model like this :
class Model
{
public int Category { get; set; }
}
In the ViewModel, there is an ObservableCollection of model "model" like :
public ObservableCollection<Model> models = new ObservableCollection<Model>();
I want to display models in the pivot controls with each model by category in pivotitem. For example, PivotItem 1 will countain all models with category 1, PivotItem 2 will countain all models with category 2, etc...
a solution would be to create new ObservableCollection for each models filtered by category but this solution remains a little heavy in my opinion. To do for example :
public ObservableCollection<Model> modelCategory1 = models.Where(x => x.category == 1) [...]
That's why I was wondering if there was not a solution directly from XAML to filter.
EDIT:
In he view, in Pivot, i have 5 pivotitems each containing one ListView
<Pivot>
<PivotItem>
<ListView ItemsSource="{x:Bind ViewModel.Models}" />
</PivotItem>
<PivotItem>
<ListView ItemsSource="{x:Bind ViewModel.Models}" />
</PivotItem>
<PivotItem>
<ListView ItemsSource="{x:Bind ViewModel.Models}" />
</PivotItem>
<PivotItem>
<ListView ItemsSource="{x:Bind ViewModel.Models}" />
</PivotItem>
<PivotItem>
<ListView ItemsSource="{x:Bind ViewModel.Models}" />
</PivotItem>
</Pivot>
EDIT 2 :
According to this Can I filter a collection from xaml? and this : [UWP]CollectionViewSource Filter? i can't filter from a CollectionViewSource from UWP, so i guess i have to create new ObservableCollection that will contains Filter result like :
private ObservableCollection<Model> _modelsCategory1;
public ObservableCollection<Model> ModelsCategory1
{
get { return _modelsCategory1; }
set { _modelsCategory1= value; NotifyPropertyChanged();
}
and :
var cat1 = from fobjs in Models
where fobjs.Category == 1
select fobjs;
ModelsCategory1 = new ObservableCollection<Model>(cat1);