title: CollectionViewSource MVVM Implementation for WPF DataGrid
body: <p>I have implemented small demo of CollectionViewSource for WPF DataGrid in MVVM. I would really appreciate any help to verify the implementation and comment on whether this is the right approach to use CollectionViewSource.</p>
  
  <pre><code>public class ViewModel : NotifyProperyChangedBase
  {       
      private ObservableCollection&lt;Movie&gt; _movieList;
      public ObservableCollection&lt;Movie&gt; MovieList
      {
          get { return _movieList; }
          set
          {
              if (this.CheckPropertyChanged&lt;ObservableCollection&lt;Movie&gt;&gt;("MovieList", ref _movieList, ref value))
                  this.DisplayNameChanged();
          }
      }
  
      private CollectionView _movieView;
      public CollectionView MovieView
      {
          get { return _movieView; }
          set
          {
              if (this.CheckPropertyChanged&lt;CollectionView&gt;("MovieView", ref _movieView, ref value))
                  this.DisplayNameChanged();
          }
      }
  
      public ViewModel()
      {
            MovieView = GetMovieCollectionView(MovieList);
      }
  
      private void DisplayNameChanged()
      {
          this.FirePropertyChanged("DisplayName");
      }
  
      public void UpdateDataGrid(string uri)
      {            
          MovieView = GetMovieCollectionView(new ObservableCollection&lt;Movie&gt;(MovieList.Where(mov =&gt; uri.Contains(mov.ID.ToString())).ToList&lt;Movie&gt;()));
      }
  
      public CollectionView GetMovieCollectionView(ObservableCollection&lt;Movie&gt; movList)
      {
          return (CollectionView)CollectionViewSource.GetDefaultView(movList);
      }
  </code></pre>
  
  <p>The XAML View :</p>
  
  <pre><code>  &lt;Window.Resources&gt;
       &lt;CollectionViewSource x:Key="MovieCollection" Source="{Binding MovieList}"&gt;
      &lt;/CollectionViewSource&gt;
    &lt;/Window.Resources&gt;
     &lt;DataGrid Name="MyDG" 
               ItemsSource="{Binding MovieView}" 
               AutoGenerateColumns="True" /&gt;
  </code></pre>
  
  <p>The Code Behind :</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
          this.Resources.Add("TagVM", new TagViewModel());
          this.DataContext = this.Resources["TagVM"];
      }
  
      private void Hyperlink_Click(object sender, RoutedEventArgs e)
      {
          string uri = ((Hyperlink)sender).NavigateUri.ToString();
          ((ViewModel)this.DataContext).UpdateDataGrid(uri);
      }
  </code></pre>
  
  <p>The Hyperlink_Click handler invokes the UpdateDataGrid method of the VM passing it comma seperated movie IDs which are then used to filter the MovieList collection using extension methods.</p>