title: Dynamically adding and moving ellipses using WPF
body: <p>I'm using WPF and having trouble dynamically/programatically adding ellipses to my grid. </p>
  
  <p>I'm dynamically allocating and placing ellipses inside myGrid. Trouble is the position on the ellipses don't change. I'm using Canvas.SetLeft and SetTop, but the ellipses still seem stuck. </p>
  
  <p>Here is the code for dynamic allocation : </p>
  
  <pre><code>{
  ...
  
         Ellipse el = new Ellipse();
                      RadialGradientBrush b = new RadialGradientBrush();
                      b.RadiusX = r * 10.0f;
                      b.RadiusY = r * 10.0f;
                      b.GradientOrigin = new Point(0.5f, 0.5f);
                      b.GradientOrigin = new Point(0.5f, 0.5f);
                      b.GradientStops.Add(new GradientStop(Colors.Green, 0.0));
                      b.GradientStops.Add(new GradientStop(Colors.Blue, 1.0));
                      el.Width = 5.0f + r * 20.0f;
                      el.Height = 5.0f + r * 20.0f;
                      el.Stroke = b;
                      SetEllipsePosition(el, p);
   this.myGrid.Children.Add(el);
  
  ...
  
  
  }
          private void SetEllipsePosition(FrameworkElement ellipse, Point j)
          {
              Canvas.SetLeft(ellipse, j.X);
              Canvas.SetTop(ellipse, j.Y);
          }
  
  
  
  
  
                      &lt;Grid Height="480" Name="myGrid" Width="640"&gt;
                          &lt;GroupBox Header="Pattern" Height="117" HorizontalAlignment="Left" Margin="10,564,0,0" Name="groupBox1" VerticalAlignment="Top" Width="238"&gt;&lt;/GroupBox&gt;
  
                          &lt;Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="33,30,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click_1" /&gt;
                          &lt;Grid Margin="6,507,408,-121"&gt;
                              &lt;RadioButton Content="Lines" Height="16" HorizontalAlignment="Left" Margin="15,18,0,0" Name="rbLines" VerticalAlignment="Top" GroupName="RenderStyles" /&gt;
                              &lt;RadioButton Content="Circles" Height="16" HorizontalAlignment="Left" Margin="15,49,0,0" Name="rbCircles" VerticalAlignment="Top" GroupName="RenderStyles" /&gt;
                          &lt;/Grid&gt;
                      &lt;/Grid&gt;
  </code></pre>