title: WPF Canvas, how to add children dynamically with MVVM code behind
body: <h1>Requirement:</h1>
  
  <p>To draw one Bitmap Image and rectangle(s) based on the collection of  points. The rectangle should exactly fit on the pixels location over the image. There is also some text need to be added inside the rectangle.</p>
  
  <p>The Image will be always only one and the rectangles will be dynamically added.</p>
  
  <h1>Current Solution:</h1>
  
  <p>Have a canvas with Image Control. Add the the dynamic code under the code behind file  ViewImageResult.xaml.cs.</p>
  
  <pre><code>    private void DrawResult(int left, int right, int width, int height)
      {
          Border bord = new Border();
          bord.BorderThickness = new Thickness(1);
          bord.BorderBrush = Brushes.Red;
          bord.Width = width;
          bord.Height = height;
          _mainCanvas.Children.Add(bord);
          Canvas.SetLeft(bord, left);
          Canvas.SetTop(bord, right);
      }
  </code></pre>
  
  <h1>Issue:</h1>
  
  <p>Since i follow MVVM pattern, the collection of points for rectangle is in my ViewModel file ViewImageResultModel.cs. I am not able to add the child rectangle dynamically from the ViewModel file.</p>