title: Canvas with Lines and Points
body: <p>I am migrating an old application and am trying to implement MVVM.  The old application has a similar interface to the one described <a href="https://stackoverflow.com/q/5276701/340045">in this post</a>.  Although it is slightly simpler.  I am not too worried about following MVVM exactly, but I would like to use this as a chance to practice.</p>
  
  <p>I have the following class:</p>
  
  <pre><code>public class LineViewModel
  {
      public ObservableCollection&lt;LinePoint&gt; Points {get;}
      public Geometry LineGeometry {get;}
  }
  </code></pre>
  
  <p>In my application view model I have a collection of lines and I would like to draw these on a Canvas, but I would also like to draw the points that make up each line.</p>
  
  <p>Here is my XAML so far:</p>
  
  <pre><code>&lt;ItemsControl ItemsSource="{Binding Lines}"&gt;
      &lt;ItemsControl.Resources&gt;
          &lt;DataTemplate DataType="{x:Type local:LineViewModel}"&gt;
              &lt;Path StrokeThickness="2.0" Stroke="Black" Data="{Binding LineGeometry}" /&gt;
          &lt;/DataTemplate&gt;
  
          &lt;DataTemplate DataType="{x:Type local:LinePoint}"&gt;
              &lt;Ellipse StrokeThickness="1.0" Stroke="Black" Fill="MistyRose" Width="8.0" Height="8.0" /&gt;
          &lt;/DataTemplate&gt;
      &lt;/ItemsControl.Resources&gt;
  
      &lt;ItemsControl.ItemsPanel&gt;
          &lt;ItemsPanelTemplate&gt;
              &lt;Canvas /&gt;
          &lt;/ItemsPanelTemplate&gt;
      &lt;/ItemsControl.ItemsPanel&gt;
  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>I can see the line being drawn and this seems to be working fine.  As you can see I have added the template for the points but I do not know how to setup the XAML to draw these.  How can I draw the points as well?</p>
  
  <p>Pulling out the Points from the line and exposing these from the application view model seems counter intuitive since it is the LineViewModel that looks after the points in a line - not the application.  I would rather not disassociate the points from the lines if I can help it.</p>
  
  <p>Thanks</p>