title: ItemsControl.ItemsSource, binding doesn't work
body: <p>This is pretty much my first attempt in data binding with WPF. When I run the program, nothing gets displayed although DataContext is set. The dummy mouse event handler checks the ItemsSource, but it is null.</p>
  
  <p>What's wrong with the binding? Is there way to debug the string-related binding stuff, or is this always like walking across a minefield in WPF?</p>
  
  <p>Remark: don't care about the wrong name "listBox1", I changed from ListBox to ItemsControl because I thought simpler is better for debugging.</p>
  
  <p><strong>Code behind:</strong></p>
  
  <pre><code>namespace TestGraphDataBinding
  {
      public partial class Window1 : Window
      {
          public ObservableCollection&lt;RectangleModel&gt; Rectangles = new ObservableCollection&lt;RectangleModel&gt;();
  
          public Window1()
          {
              InitializeComponent();
              DataContext = this;
  
              Rectangles.Add(new RectangleModel(0,0,1.0,0));
          }
  
          void whatsGoingOn(object sender, System.Windows.Input.MouseButtonEventArgs e)
          {
              Debug.Assert(listBox1.ItemsSource != null);
          }
      }
  }
  </code></pre>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Window
      x:Class="TestGraphDataBinding.Window1" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:local="clr-namespace:TestGraphDataBinding"
      Title="TestGraphDataBinding"
      Height="500"
      Width="500"&gt;
      &lt;ItemsControl
          ItemsSource="{Binding Rectangles}"
          x:Name="listBox1"
          MouseLeftButtonDown="whatsGoingOn"&gt;
          &lt;ItemsControl.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;Canvas Background="White"/&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ItemsControl.ItemsPanel&gt;
          &lt;ItemsControl.ItemTemplate&gt;
              &lt;DataTemplate
                  DataType="{x:Type local:RectangleModel}"&gt;
                  &lt;Rectangle
                      Width="10"
                      Height="10"
                      Fill="Azure"&gt;
                      &lt;Rectangle.RenderTransform&gt;
                          &lt;TransformGroup&gt;
                              &lt;TranslateTransform
                                  X="{Binding X}"
                                  Y="{Binding Y}" /&gt;
                              &lt;ScaleTransform
                                  ScaleX="{Binding Scale}"
                                  ScaleY="{Binding Scale}" /&gt;
                              &lt;RotateTransform
                                  Angle="{Binding Angle}" /&gt;
                          &lt;/TransformGroup&gt;
                      &lt;/Rectangle.RenderTransform&gt;
                  &lt;/Rectangle&gt;
              &lt;/DataTemplate&gt;
          &lt;/ItemsControl.ItemTemplate&gt;
      &lt;/ItemsControl&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Model:</strong></p>
  
  <pre><code>namespace TestGraphDataBinding
  {
      /// &lt;summary&gt;
      /// Description of RectangleModel.
      /// &lt;/summary&gt;
      public class RectangleModel
      {
          public double X {get; private set;}
          public double Y {get; private set;}
          public double Scale {get; private set;}
          public double Angle {get; private set;}
  
          public RectangleModel(double x, double y, double scale, double angle)
          {
              X = x;
              Y = y;
              Scale = scale;
              Angle = angle;
          }
      }
  }
  </code></pre>