title: At what point is a UIElement loaded?
body: <p>I have the following code:</p>
  <pre><code>&lt;Window x:Class=&quot;Demo.MainWindow&quot;
          xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
          xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
          xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
          xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
          mc:Ignorable=&quot;d&quot;
          Title=&quot;MainWindow&quot; Height=&quot;450&quot; Width=&quot;800&quot;&gt;
      &lt;Canvas Name=&quot;Canvas_Main&quot; /&gt;
  &lt;/Window&gt;
  
  </code></pre>
  <pre><code>public partial class MainWindow : Window
  {
  
      public MainWindow()
      {
          InitializeComponent();
          Loaded += MainWindow_Loaded;
      }
  
      private void MainWindow_Loaded(Object sender, RoutedEventArgs e)
      {
          Rectangle lastRectangle = null;
          Random random = new Random(0);
          for (Int32 counter = 0; counter &lt; 5; counter++)
          {
              Rectangle rectangle = new Rectangle();
              rectangle.Fill = Brushes.Blue;
              rectangle.Width = random.Next(100, 200);
              rectangle.Height = counter * 100;
              Canvas_Main.Children.Add(rectangle);
              if (lastRectangle == null) {
                  Canvas.SetLeft(rectangle, 0);
                  Canvas.SetTop(rectangle, 0);
              }
              else
              {
                  Canvas.SetLeft(rectangle, lastRectangle.ActualWidth);
                  Canvas.SetTop(rectangle, 0);
              }
              lastRectangle = rectangle;
          }
      }
  
  }
  </code></pre>
  <p>This isn't working as expected (laying each rectangle diagonally next to each other), as <code>lastRectangle.ActualWidth</code> is 0. As I understand things from <a href="https://stackoverflow.com/a/1695518/14385915">this answer</a>, it is because lastRectangle has not been measured and arranged.</p>
  <p>I am curious, at what point would the measuring and arranging be done, if not when added to a container that is already visible and loaded?</p>