title: C# WPF Binding to indexed property - what am I doing wrong?
body: <p>I have recently discovered indexed properties. This looks like the perfect solution to the scenario in which the data I am working with would best be expressed in a collection, yet still needs to be implemented as a property that can be used in XAML databinding. I started with just a test of creating indexed properties, and I had no problems there, but I just don't seem to be able to get the binding to work. </p>
  
  <p>Can anyone point out where I'm going wrong?</p>
  
  <p>Here is the test class with a nested class to create the indexed property:</p>
  
  <pre><code>public class TestListProperty 
  {
  
      public readonly ListProperty ListData;
  
      //---------------------------
      public class ListProperty : INotifyPropertyChanged 
      {
          private List&lt;string&gt; m_data;
  
          internal ListProperty()
          {
              m_data = new List&lt;string&gt;();
          }
  
          public string this[int index]
          {
              get
              {
                  if ( m_data.Count &gt; index )
                  {
                      return m_data[index]; 
                  }
                  else
                  {
                      return "Element not set for " + index.ToString();
                  }
              }
              set
              {
                  if ( m_data.Count &gt; index )
                  {
                      m_data[index] = value;
                  }
                  else
                  {
                      m_data.Insert( index, value );
                  }
                  OnPropertyChanged( "Item[]" );
                  Console.WriteLine( value );
              }
          }
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          protected virtual void OnPropertyChanged( string propertyName )
          {
              PropertyChangedEventHandler handler = PropertyChanged;
              if ( handler != null ) handler( this, new PropertyChangedEventArgs( propertyName ) );
          }
  
      }
      //---------------------------
      public TestListProperty()
      {
          ListData = new ListProperty();
      }
  
  }
  </code></pre>
  
  <p>Here is the XAML:</p>
  
  <pre><code>&lt;Window x:Class="TestIndexedProperties.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Grid&gt;
  
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition/&gt;
              &lt;RowDefinition/&gt;
              &lt;RowDefinition/&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;TextBox Width="200" Grid.Row="0" Text="{Binding Path=ListData[0], Mode=TwoWay}" /&gt;
          &lt;TextBox Width="200" Grid.Row="1" Text="{Binding Path=ListData[1], Mode=TwoWay}" /&gt;
          &lt;TextBox Width="200" Grid.Row="2" Text="{Binding Path=ListData[2], Mode=TwoWay}" /&gt;
  
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And here is the Window code:</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
  
          TestListProperty test = new TestListProperty();
  
          this.DataContext = test;
  
          test.ListData[0] = "ABC";
          test.ListData[1] = "Pleeez 2 wurk?";
          test.ListData[2] = "Oh well";
  
      }
  }
  </code></pre>
  
  <p>Thanks for any and all help!</p>