title: How to bind collection dependency property in UserControl
body: <p>This is not a duplicate! When I failed I tried to look to similar posts but without success. I cannot understand why <code>OnUCItemsSourceChanged</code> is not called? I'm pretty sure that I miss something simple but I cannot find it.</p>
  
  <p>I have <code>Window</code> that contains <code>UserControl1</code> which has attached collection property that is bound to <code>Window</code>'s <code>WindowCollection</code> collection. I expect <code>UserControl1.OnUCItemsSourceChanged</code> to be called when I add items to <code>WindowCollection</code>. But it doesn't happen. </p>
  
  <p>What I miss?</p>
  
  <p><strong>Window1.xaml.cs</strong></p>
  
  <pre><code>public partial class Window1 : Window
  {
      public ObservableCollection&lt;long&gt; WindowCollection { get; set; }
      public Window1()
      {
          InitializeComponent();
  
          DataContext = this;
  
          WindowCollection = new ObservableCollection&lt;long&gt;();
      }
  
      private void Button_Click(object sender, RoutedEventArgs e)
      {
          WindowCollection.Add(1);
          WindowCollection.Add(2);
      }
  }
  </code></pre>
  
  <p><strong>Window1.xaml</strong></p>
  
  <pre><code>&lt;StackPanel&gt;
      &lt;uc:UserControl1 UCItemsSource="{Binding Path=WindowCollection}" /&gt;
      &lt;Button Content="Refresh" Click="Button_Click" /&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p><strong>UserControl1.xaml.cs</strong></p>
  
  <pre><code>public static readonly DependencyProperty UCItemsSourceProperty = DependencyProperty.Register("UCItemsSource", typeof(IEnumerable), typeof(UserControl1), new PropertyMetadata(null, new PropertyChangedCallback(OnUCItemsSourceChanged)));
  
  public IEnumerable UCItemsSource
  {
      get { return (IEnumerable)GetValue(UCItemsSourceProperty ); }
      set { SetValue(UCItemsSourceProperty , value); }
  }
  
  public ObservableCollection&lt;MyItem&gt; UCItems { get; set; }
  
  private static void OnUCItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  {
      var control = d as UserControl1;
      var items = e.NewValue as ObservableCollection&lt;long&gt;;
  
      foreach (var item in items)
     {
           control.UCItems.Add(new MyItem(item));
     }
  }
  </code></pre>
  
  <p><strong>UserControl1.xaml</strong></p>
  
  <pre><code>&lt;ItemsControl ItemsSource="{Binding UCItems}" ... /&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong>
  This is <a href="https://drive.google.com/file/d/0B_j2rCBlhOaNN0hrckpNVGEzNDg/edit?usp=sharing" rel="nofollow">link</a> to my test project</p>