title: UWP best way to use x:Bind and filter ObservableCollection
body: <p>I have an UWP application. </p>
  
  <p>One view with a <strong>pivot</strong> control.</p>
  
  <p>One associated ViewModel.</p>
  
  <p>One model like this :</p>
  
  <pre><code>class Model
  {
      public int Category { get; set; }
  }
  </code></pre>
  
  <p>In the ViewModel, there is an ObservableCollection of model "model" like :</p>
  
  <pre><code>public ObservableCollection&lt;Model&gt; models = new ObservableCollection&lt;Model&gt;();
  </code></pre>
  
  <p>I want to display models in the pivot controls with each model <strong>by category</strong> in pivotitem. For example, PivotItem 1 will countain all models with category 1, PivotItem 2 will countain all models with category 2, etc...</p>
  
  <p>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 :</p>
  
  <pre><code>public ObservableCollection&lt;Model&gt; modelCategory1 = models.Where(x =&gt; x.category == 1) [...]
  </code></pre>
  
  <p>That's why I was wondering if there was not a solution directly from XAML to filter.</p>
  
  <p>EDIT:</p>
  
  <p>In he view, in Pivot, i have 5 pivotitems each containing one ListView</p>
  
  <pre><code>&lt;Pivot&gt;
      &lt;PivotItem&gt;
          &lt;ListView ItemsSource="{x:Bind ViewModel.Models}" /&gt;
      &lt;/PivotItem&gt;
      &lt;PivotItem&gt;
          &lt;ListView ItemsSource="{x:Bind ViewModel.Models}" /&gt;
      &lt;/PivotItem&gt;
      &lt;PivotItem&gt;
          &lt;ListView ItemsSource="{x:Bind ViewModel.Models}" /&gt;
      &lt;/PivotItem&gt;
      &lt;PivotItem&gt;
          &lt;ListView ItemsSource="{x:Bind ViewModel.Models}" /&gt;
      &lt;/PivotItem&gt;
      &lt;PivotItem&gt;
          &lt;ListView ItemsSource="{x:Bind ViewModel.Models}" /&gt;
      &lt;/PivotItem&gt;
  &lt;/Pivot&gt;
  </code></pre>
  
  <p>EDIT 2 :</p>
  
  <p>According to this <a href="https://stackoverflow.com/questions/4923935/can-i-filter-a-collection-from-xaml">Can I filter a collection from xaml?</a> and this : <a href="https://social.msdn.microsoft.com/Forums/sqlserver/en-US/15f3c875-e321-4eac-92ae-2f6226c33355/uwpcollectionviewsource-filter?forum=wpdevelop" rel="nofollow noreferrer">[UWP]CollectionViewSource Filter?</a> i can't filter from a CollectionViewSource from UWP, so i guess i have to create new ObservableCollection that will contains Filter result like : </p>
  
  <pre><code>private ObservableCollection&lt;Model&gt; _modelsCategory1; 
  public ObservableCollection&lt;Model&gt; ModelsCategory1
  { 
      get { return _modelsCategory1; } 
      set { _modelsCategory1= value; NotifyPropertyChanged(); 
  } 
  </code></pre>
  
  <p>and : </p>
  
  <pre><code>var cat1 = from fobjs in Models 
           where fobjs.Category == 1 
           select fobjs;
  ModelsCategory1  = new ObservableCollection&lt;Model&gt;(cat1);
  </code></pre>