title: WPF: DataBinding a PointCollection for a custom UIElement
body: <p>I'm trying to make a WPF <code>UIElement</code> that does some special rendering.</p>
  
  <p>The problem is that I can't get databinding to work for a <code>PointCollection</code>.  Inside <code>OnRender()</code> of the <code>GraphElement</code>, the Points property is null, which doesn't make any sense to me.</p>
  
  <pre><code>class GraphElement : UIElement
  {
      public static readonly DependencyProperty PointsProperty = DependencyProperty.Register(
          "Points",
          typeof(PointCollection),
          typeof(GraphElement),
          new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));            
  
      public PointCollection Points
      {
          get { return (PointCollection)GetValue(PointsProperty); }
          set { SetValue(PointsProperty, value); }
      }
  
      protected override void OnRender(DrawingContext drawingContext)
      {
          base.OnRender(drawingContext);
  
          //Points is null
          Debug.Assert(Points != null);
      }
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>class TestViewModel : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged;
  
      private PointCollection _viewModelPoints;
      public PointCollection ViewModelPoints
      {
          get { return _viewModelPoints; }
          set
          {
              _viewModelPoints = value;
              if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("ViewModelPoints"));
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;Window x:Class="TestApp.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:TestApp"
      Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
      &lt;Canvas&gt;
          &lt;local:GraphElement Points="{Binding Path=ViewModelPoints}"/&gt;
      &lt;/Canvas&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <hr>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  
  namespace TestApp
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              var testViewModel = new TestViewModel();
              testViewModel.ViewModelPoints = new PointCollection();
              testViewModel.ViewModelPoints.Add(new Point(0.0, 0.0));
              DataContext = testViewModel;
              InitializeComponent();
          }
      }
  }
  </code></pre>