title: Add n rectangles to canvas with MVVM in WPF
body: <p>I want to add a set of rectangles to the main window of my mvvm application. In my viewModel I've got a collection of objects which I convert to System.Windows.Shapes.Rectangle classes with a converter (code below):</p>
  
  <p>ViewModel:</p>
  
  <pre><code>RecognizedValueViewModel 
  {
      public ObservableCollection&lt;BarcodeElement&gt; BarcodeElements
      {
          get { return _BarcodeElements; }
          set { _BarcodeElements = value; }
      }
  
      public RecognizedValueViewModel()
      {
          BarcodeElements = InitializeBarcodeElements();
      }
  }
  </code></pre>
  
  <p>Converter:</p>
  
  <pre><code>public BarcodeElementToRectangleConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          Rectangle barcodeRectangle = GetRectangleFromBarcodeElement(value as BarcodeElement);
  
          return barcodeRectangle;
      }
  }
  </code></pre>
  
  <p>The rectangles should be shown in a canvas in my MainWindow:</p>
  
  <pre><code>&lt;Canvas x:Name="Canvas_Image_Main"&gt;
      &lt;!-- Show rectangles here --&gt;
  &lt;/Canvas&gt;
  </code></pre>
  
  <p>I would add Rectangles to canvas in code but I don't now how many rectangles are there at runtime. Is there a way how I can achieve this? Tank you.</p>