title: How do I center a TextBlock to a given position
body: <p>A TextBlock should be centered to a position x (or y when Orientation is vertical).
  I implemented:</p>
  
  <pre><code>TextBlock text = new TextBlock();
  // Some code to define text, font, etc. here
  
  // Turn if Orientation is vertical
  if (Orientation == Orientation.Vertical) 
  {
    text.RenderTransform = new RotateTransform() { Angle = 270 };
  }
  
  // Update, then ActualWidth is set correctly
  text.UpdateLayout();
  
  // Position of label centered to given position
  double halfWidth = text.ActualWidth / 2;
  double x1 = (Orientation == Orientation.Horizontal) ? x - halfWidth : x;
  double y1 = (Orientation == Orientation.Horizontal) ? y : y + halfWidth;
  
  Canvas.SetLeft(text, x1);
  Canvas.SetTop(text, y1);
  
  Children.Add(text); // Add to Canvas
  </code></pre>
  
  <p>This works actual fine, but is it possible to do this without <code>UpdateLayout</code>. If I remove <code>UpdateLayout</code>, then I do not get the position I am looking for, because ActualWidth is (of course) zero.</p>