title: How to properly bind a DependencyProperty to a CollectionViewSource?
body: <p>I am beginner to WPF and I am facing problem while trying to bind a Dependency Property as the source of a <code>CollectionViewSource</code>.</p>
  <p>The user control exposes a <code>DependencyProperty</code> of type <code>List</code>. It is used to present the data in a <code>DataGrid</code> with the help of <code>CollectionViewSource</code> (using it for Filtering, Grouping and Sorting operations).</p>
  <p>My <code>MainWindow XAML</code>:</p>
  <pre><code>&lt;Window&gt;
     &lt;local:CustomUserControl x:Name=&quot;CustomUCDataGrid&quot; ListToDisplay=&quot;{Binding listFromDB}&quot;/&gt;
  &lt;Window&gt;
  </code></pre>
  <p>My <code>MainWindow.cs</code>:</p>
  <pre><code>public partial class MainWindow : Window
  {
      public List&lt;customType&gt; listFromDB{get;set;}
      public MainWindow{
         listFromDB = GetListFromDB();
         InitializeComponent();
         this.DataContext = this;
      }
  }
  </code></pre>
  <p><code>CustomUserControl.xaml</code> looks something like:</p>
  <pre><code>&lt;UserControl x:Name=&quot;ParentNode&quot;&gt;
     &lt;DataGrid DataContext=&quot;{Binding ElementName=ParentNode}&quot;&gt;
        &lt;StackPanel&gt;
           &lt;DataGrid x:Name=&quot;DirectDataGrid&quot; ItemSource=&quot;{Binding ListToDisplay}&quot;/&gt;
           &lt;DataGrid x:Name=&quot;DataGridWithCVS&quot; ItemsSource=&quot;{Binding cvsList.View}&quot;/&gt;
        &lt;/StackPanel&gt;
     &lt;/DataGrid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  <p><code>CustomUserControl.xaml.cs</code> looks like:</p>
  <pre><code>public partial class CustomUserControl: UserControl
  {
      public List&lt;customType&gt; ListToDisplay{
          get { return (List&lt;customType&gt;)GetValue(ListToDisplayProperty); }
          set { SetValue(ListToDisplayProperty, value); }
      }
  
      public static readonly DependencyProperty ListToDisplayProperty=
              DependencyProperty.Register(&quot;ListToDisplay&quot;, typeof(List&lt;customType&gt;),
                typeof(CustomUserControl));
  
      public CollectionViewSource cvsList { get; set; }
  
      public CustomUserControl{
          InitializeComponent();
           cvsList = new CollectionViewSource();
           cvsList.Source = ListToDisplay;
           DataGridWithCVS.ItemsSource = CollectionViewSource.GetDefaultView(cvsList);
      }
  }
  </code></pre>
  <p>Here the DataGrid with name <strong>&quot;DirectDataGrid&quot;</strong> has <em><strong>no problem</strong></em> in displaying the data supplied to it from the MainWindow, but the DataGrid with name <strong>&quot;DataGridWithCVS&quot;</strong> doesn't display any data. Couldn't find any errors while debugging.</p>
  <p><em><strong>Things I have already Tried:</strong></em></p>
  <ul>
  <li>Define the CollectionViewSource as a StaticResource inside the CustomUserControl XAML - Can't implement this because, the UserControl doesn't use the DataContext set from the MainWindow. It uses its own DataContext without overriding the MainWindow's DataContext. (<code>&lt;UserControl x:Name=&quot;ParentNode&quot;&gt; &lt;DataGrid DataContext=&quot;{Binding ElementName=ParentNode}&quot;&gt;...</code>).</li>
  </ul>