title: ListBox ItemsSource dynamic filter WPF
body: <p>I want to make a UI virtualization via the datasource.</p>
  
  <p>The idea is to "Filter" what i send to the UI (a listbox in my case).</p>
  
  <p>I noticed that the ItemsSource (an observable collection) is read once and that changing the Filter does not trigger refreshing...</p>
  
  <p>I don't understand why
  Thanks
  Jonathan</p>
  
  <hr>
  
  <p>I'll try to be more clear :</p>
  
  <p>I have CollectionViewSource:</p>
  
  <pre><code>&lt;CollectionViewSource x:Key="MyItemView"
                                    Source="{Binding Path=Model.CurrentItem}" /&gt;
  </code></pre>
  
  <p>Then use this datasource in my ListBox:</p>
  
  <pre><code>&lt;ListBox x:Name="myListBox"
                   ItemsSource="{Binding Source={StaticResource MyItemView}}"
  </code></pre>
  
  <p>I thought to implement a converter that would return a filtered collection (base on the current date):</p>
  
  <pre><code>&lt;ListBox x:Name="myListBox"
                   ItemsSource="{Binding Source={StaticResource MyItemView}, Converter={StaticResource FilterByTime}, ConverterParameter=CurrentDate }"
  </code></pre>
  
  <p>Which i implemented this way:</p>
  
  <pre><code>public class FilterByTimeConverter : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
          {
              if (value != null)
              {
                  System.Windows.Data.ListCollectionView list = value as System.Windows.Data.ListCollectionView;
  
                  var model = DI.Resolve&lt;ApplicationModel&gt;();
  
                  list.Filter = delegate(object item) 
                  { 
                      bool r= (((MyModel)item).OriginalDate &gt; model.TimeLine.CurrentDate.AddMonths(-1) 
                          &amp;&amp; (((MyModel)item).OriginalDate &lt; model.TimeLine.CurrentDate.AddMonths(1)));
  
                     // Console.WriteLine ("{0}&lt;{1}&lt;{2} : {3}",model.MyListBox.CurrentDate.AddMonths(-1),((MyModel)item).OriginalDate ,model. MyListBox.CurrentDate.AddMonths(1),r.ToString());
                      return r;
                  };
  
                  return list;
              }
  
              return DependencyProperty.UnsetValue;
          }
  </code></pre>
  
  <p>This works fine...but only when bounf the first time.
  When the Current Date is changed and that the filter is changed, the list is not updated.</p>
  
  <p>Perhaps i should listen to the CurrentDate PropertyChange, but i'm confused how to do this</p>
  
  <p>Thanks
  Jonathan</p>