title: canvas animation - not working in loop
body: <p>Hello I can't understand the problem that I have</p>
  
  <pre><code>private void StartReplay(object sender, RoutedEventArgs e)
      {
          for (int i = 0; i &lt;= 40; i++)
          {
              if (leftCounter &lt; 20)
              {
                  leftCounter++;
                  leftCounter2 = leftCounter;
                  Canvas.SetLeft(Kwadracik, leftCounter);
              }
              else
              {
                  leftCounter2--;
  
                  Canvas.SetLeft(Kwadracik, leftCounter2);
              }
          }
      }
  </code></pre>
  
  <p>Now 2 ways</p>
  
  <p>1) If I'll delete the loop than every time I'll click a button the leftCounter will be incremented by 1 and the canvas will be moved. 20 to right than to left as many as many click I'll make. It works as expected. First to the right than to the left</p>
  
  <p>2) When I run it with loop when I click the button the loop will go. But it won't work as I expect it to work. I've expected that it will go 20 to right and than 20 to left (20+20 = 40). But no. It is not moving in two sides. It's just stand because it is jumping to the end. I can't see the move to the right. Even if I'll get small delay on every loop step the GUI is freezing and it is unfreezing after the loop ends and the element is where it was</p>
  
  <p>Why there is this kind of diffrence ? How can I overpass it ?</p>
  
  <p>XAML that is standing behind this</p>
  
  <pre><code>    &lt;Canvas x:Name="canvas" HorizontalAlignment="Center" VerticalAlignment="Center"&gt;
          &lt;Rectangle Name="Kwadracik" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Fill="Blue" /&gt;
      &lt;/Canvas&gt;
  </code></pre>