title: Are There Any CollectionViewSource Alternative with Generic?
body: <p>For my WPF application, I need CollectionViewSource to enable selection, filtering, sorting, and grouping in a collection. But CollectionViewSource is not a type safe collection like IList, the property View.CurrentItem is an object for example. We need to cast the items if we use them.</p>
  
  <p>Are there any CollectionViewSource alternatives that support Generic?
  Or maybe anybody know the reason why CollectionViewSource is not a generic?</p>
  
  <p>=============================</p>
  
  <p>I made a generic CollectionViewSource based on standard CollectionViewSource.
  Any comment whether it is a better alternative for collection class that is instantiated outside XAML? Or there is another better alternative?</p>
  
  <p>Edit 1: Add Generic CollectionViewSource</p>
  
  <pre><code>namespace Data
  {
      using System.Collections.Generic;
      using System.Linq;
      using System.Windows.Data;
  
      public class CollectionViewSource&lt;T&gt; : CollectionViewSource
      {
          public T CurrentItem =&gt; this.View != null ? (T)this.View.CurrentItem : default(T);
  
          public new IEnumerable&lt;T&gt; Source
          {
              get
              {
                  return (IEnumerable&lt;T&gt;)base.Source;
              }
  
              set
              {
                  base.Source = value;
              }
          }
  
          public IEnumerable&lt;T&gt; ViewItems =&gt; this.View != null ? Enumerable.Cast&lt;T&gt;(this.View) : (IEnumerable&lt;T&gt;)null;
  
          public CollectionViewSource(IEnumerable&lt;T&gt; source)
          {
              this.Source = source;
          }
  
          public bool Contains(T item)
          {
              return this.View != null &amp;&amp; this.View.Contains(item);
          }
  
          public IEnumerable&lt;T&gt; Groups()
          {
              return this.View.Groups.Cast&lt;T&gt;();
          }
  
          public void MoveCurrentTo(T item)
          {
              this.View?.MoveCurrentTo(item);
          }
      }
  }
  </code></pre>