title: Data binding doesn't work with my dependency property
body: <p>I'm developing a WPF application with .NET Framework 4 and <a href="http://www.galasoft.ch/mvvm/" rel="nofollow noreferrer">MVVM Light Toolkit</a>
  I created a custom user control which only contains a <em>DataGrid</em>:</p>
  <pre><code>&lt;UserControl
      x:Class=&quot;PadacEtl.Matcher.Views.LaraDataGrid&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; 
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; 
      mc:Ignorable=&quot;d&quot; 
      d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;300&quot;
      DataContext=&quot;{Binding}&quot;&gt;
  
      &lt;DataGrid ItemsSource=&quot;{Binding}&quot; SelectionChanged=&quot;SelectionChanged&quot;&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Header=&quot;Value&quot; Binding=&quot;{Binding Model.Value}&quot; /&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  <p>This control defines a dependency property <em>SelectedItems</em>:</p>
  <pre><code>public partial class CustomDataGrid : UserControl
  {
      public IEnumerable&lt;ItemViewModel&gt; SelectedItems
      {
          get { return (IEnumerable&lt;ItemViewModel&gt;)GetValue(SelectedItemsProperty); }
          set { SetValue(SelectedItemsProperty, value); }
      }
  
      public static readonly DependencyProperty SelectedItemsProperty =
          DependencyProperty.Register(&quot;SelectedItems&quot;, typeof(IEnumerable&lt;ItemViewModel&gt;),
              typeof(CustomDataGrid), new PropertyMetadata(new List&lt;ItemViewModel&gt;()));
  
      public CustomDataGrid()
      {
          InitializeComponent();
      }
  
      private void SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
          var dataGrid = sender as DataGrid;
          SelectedItems = dataGrid.SelectedItems.Cast&lt;ItemViewModel&gt;();
      }
  }
  </code></pre>
  <p>Finally, this custom user control is used in a view, defined as follow:</p>
  <pre><code>&lt;Window x:Class=&quot;Project.Views.MainView&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:uc=&quot;clr-namespace:Project.Views&quot;
      Title=&quot;Project&quot;
      Height=&quot;700&quot; Width=&quot;1050&quot;
      DataContext=&quot;{Binding Source={StaticResource Locator}, Path=Main}&quot;&gt;
  
      &lt;Window.Resources&gt;
          &lt;ResourceDictionary Source=&quot;Styles.xaml&quot; /&gt;
      &lt;/Window.Resources&gt;
  
      &lt;Grid&gt;
          &lt;uc:CustomDataGrid DataContext=&quot;{Binding Items}&quot;
              SelectedItems=&quot;{Binding SelectedItems}&quot; /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  <p>With the corresponding <em>ViewModel</em>:</p>
  <pre><code>public class MainViewModel : ViewModelBase
  {
      public ObservableCollection&lt;ItemViewModel&gt; Items { get; private set; }
  
      private IEnumerable&lt;ItemViewModel&gt; selectedItems = new List&lt;ItemViewModel&gt;();
      public IEnumerable&lt;ItemViewModel&gt; SelectedItems
      {
          get { return selectedItems; }
          set
          {
              if (value != selectedItems)
              {
                  selectedItems = value;
                  RaisePropertyChanged(() =&gt; SelectedItems);
               }
          }
      }
  
      public MainViewModel()
      {
          //Something useful to feed Items
      }
  }
  </code></pre>
  <p><strong>My problem is</strong>: When I select one or more rows from my <em>CustomDataGrid</em>, <em>SelectedItems</em> from <em>MainViewModel</em> is not updated. I think I didn't wired something well but I don't find what.</p>
  <p>Any idea?</p>