title: Binding to an IEnumerable<object> dependency property
body: <p>I've created a custom control, called <code>SearchableCheckBoxList</code> (derived from <code>UserControl</code>). In this control I have an <code>ItemsControl</code>, which contains Items of type <code>Entry</code>, as defined here:</p>
  
  <pre><code>public class Entry : BindableBase
  {
      public Entry(object content)
          : this(content, false)
      { }
  
      public Entry(object content, bool isChecked)
      {
          Content = content;
          IsChecked = isChecked;
      }
  
      private bool _isChecked;
      public bool IsChecked
      {
          get { return _isChecked; }
          set { this.SetProperty(ref this._isChecked, value); }
      }
  
      private object _content;
      public object Content
      {
          get { return _content; }
          set { SetProperty(ref _content, value); }
      }
  
  }
  </code></pre>
  
  <p>In my code behind, I also have a <code>DependencyProperty</code> called <code>ItemsSource</code> (of type <code>IEnumerable</code>) which takes a collection of items (of any type) and converts them to an <code>Entry</code> type. That is, for each element in the collection I'm creating a new Entry item and storing that element in the Content property of the Entry item, like this:</p>
  
  <pre><code>foreach (var item in ItemsSource)
     itemsControl.Items.Add(new Entry(item));
  </code></pre>
  
  <p>I'm doing this because in my <code>ItemsControl</code> I have a checkbox next to each item, and the user can click on one or more checkboxes to select multiple items which will reflect on the IsChecked property of each <code>Entry</code> item. </p>
  
  <p>I have another dependency property in my code behind called <code>SelectedItems</code>, defined as such:</p>
  
  <pre><code>public IEnumerable&lt;object&gt; SelectedItems
  {
      get { return (IEnumerable&lt;object&gt;)GetValue(SelectedItemsProperty); }
      set { SetValue(SelectedItemsProperty, value); }
  }
  public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register("SelectedItems", typeof(IEnumerable&lt;object&gt;), typeof(SearchableCheckBoxList), 
                                                                      new PropertyMetadata(default(IEnumerable&lt;object&gt;)));
  </code></pre>
  
  <p>Every time an item is checked or unchecked in my itemscontrol, I am updating the above DP as such:</p>
  
  <pre><code>private void checkBox_CheckChanged(object sender, RoutedEventArgs e)
  {
      var checkBox = (CheckBox)sender;
  
      // Get entry from the content presenter
      var entry = ((Entry)(((ContentPresenter)checkBox.Content).DataContext));
  
      // Set its checked value based on the checkbox's checked value
      entry.IsChecked = (bool)checkBox.IsChecked;
  
      // Update selected items collection
      SelectedItems = itemsControl.Items.Cast&lt;Entry&gt;().Where(i =&gt; i.IsChecked).Select(i =&gt; i.Content).ToList();
  
  }
  </code></pre>
  
  <p>In my main program, I am using this control as such:</p>
  
  <pre><code>&lt;controls:SearchableCheckBoxList SelectedItems="{Binding SelectedCities, Mode=TwoWay}"
                                   ItemsSource="{Binding CityCollection, Mode=OneTime}"/&gt;                       
  </code></pre>
  
  <p>And in my viewmodel <code>SelectedCities</code> and <code>CityCollection</code> are defined as such:</p>
  
  <pre><code>private ObservableCollection&lt;CityModel&gt; _cityCollection;
  public ObservableCollection&lt;CityModel&gt; CityCollection
  {
      get { return _cityCollection; }
      set { SetProperty(ref _cityCollection, value); }
  }
  
  private List&lt;object&gt; _selectedCities = new List&lt;object&gt;();
  public List&lt;object&gt; SelectedCities
  {
      get { return _selectedCities; }
      set { SetProperty(ref _selectedCities, value); }
  }
  </code></pre>
  
  <p>The control looks like <a href="http://i.stack.imgur.com/0S3wq.png" rel="nofollow">this</a>.</p>
  
  <p>Now, all this works fine and the bindings are updating as expected. The problem I'm having is that for this to work SelectedCities have to be defined as <code>List&lt;object&gt;</code>. I want to define SelectedCities as <code>List&lt;CityModel&gt;</code>, but if I do this the setter of my property is always called with a value of null. I can't seem to figure out why or what to do.</p>
  
  <p><strong>EDIT</strong> As requested, here is <a href="http://pastebin.com/rWc6e6N4" rel="nofollow">SearchableCheckBoxList.xaml</a> and <a href="http://pastebin.com/HGFaqBRN" rel="nofollow">SearchableCheckBoxList.cs</a></p>