title: A trouble regarding the data binding of the SelectedItem of a custom ListView
body: <p>I have a custom StringListView as shown below, but the data binding of the SelectedItem does not correctly work.</p>
  
  <pre><code>&lt;UserControl x:Class="hogeWPF2.StringListView"&gt;
      &lt;Grid DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"&gt;
          &lt;ListView ItemsSource="{Binding PersonsSource}" SelectedItem="{Binding SelectedPerson}"
                  SelectionMode="Single" &gt;
              &lt;ListView.View&gt;
                  &lt;GridView&gt;                      
                      &lt;GridViewColumn Header="Age"&gt;
                          &lt;GridViewColumn.CellTemplate&gt;
                              &lt;DataTemplate&gt;
                                  &lt;TextBlock TextAlignment="Right" Text="{Binding Age}"/&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/GridViewColumn.CellTemplate&gt;
                      &lt;/GridViewColumn&gt;
                  &lt;/GridView&gt;
              &lt;/ListView.View&gt;
          &lt;/ListView&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  
  public partial class StringListView : UserControl
  {
      public static readonly DependencyProperty PersonsSourceProperty = DependencyProperty.Register(
          "PersonsSource", typeof (ObservableCollection&lt;Person&gt;), typeof (StringListView), new PropertyMetadata(default(ObservableCollection&lt;Person&gt;)));
  
      public ObservableCollection&lt;Person&gt; PersonsSource
      {
          get { return (ObservableCollection&lt;Person&gt;) GetValue(PersonsSourceProperty); }
          set { SetValue(PersonsSourceProperty, value); }
      }
  
      public static readonly DependencyProperty SelectedPersonProperty = DependencyProperty.Register(
          "SelectedPerson", typeof (Person), typeof (StringListView), new PropertyMetadata(default(Person)));
  
      public Person SelectedPerson
      {
          get { return (Person) GetValue(SelectedPersonProperty); }
          set { SetValue(SelectedPersonProperty, value); }
      }
  
      public StringListView()
      {
          InitializeComponent();
      }
  }
  </code></pre>
  
  <p>In the MainWindow, I put my custom ListView as follows.</p>
  
  <pre><code>&lt;Window x:Class="hogeWPF2.MainWindow"&gt;
      &lt;Grid DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"&gt;
          &lt;local:StringListView PersonsSource="{Binding Persons}" SelectedPerson="{Binding SelectedPerson}"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  
  public partial class MainWindow : Window, INotifyPropertyChanged
  {      
      private ObservableCollection&lt;Person&gt; _persons;
      public ObservableCollection&lt;Person&gt; Persons
      {
          get { return _persons; }
          private set
          {
              _persons = value;
              OnPropertyChanged();
          }
      }
  
      private Person _selectedPerson;
      public Person SelectedPerson
      {
          get { return _selectedPerson; }
          set
          {
              _selectedPerson = value;
              OnPropertyChanged();
          }
      }
  
      public MainWindow()
      {
          InitializeComponent();
          Persons = new ObservableCollection&lt;Person&gt;
          {
              new Person{ Age = 25},
              new Person{ Age = 30},
              new Person{ Age = 35},
          };
      }
  }
  
  public class Person : INotifyPropertyChanged
  {
      private int _age;
      public int Age
      {
          get { return _age; }
          set
          {
              _age = value;
              OnPropertyChanged();
          }
      }
  }
  </code></pre>
  
  <p>If I don't use my custom StringListView and instead directly write the contents of it in XAML of the MainWindow, the SelectedItem is correctly recognized. However, if I use my custom StringListView, the data binding fails to work and the SelectedItem seems to be always null. I guess the root cause exists in the Dependency Property SelectedPerson in StringListView class, since there happen no errors if I don't use it. But I don't understand how to revise it. Does anyone have an answer?</p>