Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After copying your code into an empty WPF application, I'm afraid to tell you that your code works just fine:</p> <p><img src="https://i.stack.imgur.com/a1pAb.png" alt="enter image description here"></p> <p>All I did was to set the <code>Grid.Background</code> to red and the <code>TextBlock.Background</code> to black to clarify the situation:</p> <pre><code>&lt;Grid Width="159" Height="159"&gt; &lt;Grid.Background&gt; &lt;SolidColorBrush Color="Red"/&gt; &lt;/Grid.Background&gt; &lt;TextBlock Background="Black" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" FontSize="28" Foreground="White"&gt;qwerty&lt;/TextBlock&gt; </code></pre> <p>Therefore, I can only assume that you have a problem elsewhere in your code.</p> <p>UPDATE >>></p> <p>Sorry, you're right, I <em>did</em> misunderstand you. However, after testing your <code>C#</code> code, the story is just the same:</p> <p><img src="https://i.stack.imgur.com/Ya2KV.png" alt="enter image description here"></p> <p>This <em>might</em> look like the same image, but it <em>actually</em> comes from <em>your</em> <code>C#</code> code... I made a couple of little changes, but nothing that affected the position of the <code>TextBlock</code>:</p> <pre><code>Grid grid = new Grid(); grid.Background = Brushes.Red; grid.Width = grid.Height = 159.0; TextBlock textBlock = new TextBlock(); textBlock.Text = "qwerty"; textBlock.Background = Brushes.Black; textBlock.FontWeight = FontWeights.Bold; textBlock.HorizontalAlignment = HorizontalAlignment.Center; textBlock.VerticalAlignment = VerticalAlignment.Center; textBlock.FontSize = 28; textBlock.Foreground = Brushes.White; grid.Children.Add(textBlock); this.Content = grid; </code></pre> <p>If you put this code into a new WPF project, you'll see that it works just fine, so that only leaves your <code>WriteableBitmap</code> object as the culprit of this problem... what are you using that for? If you're just adding it to your UI, then you can simply add the controls to the <code>Window</code> directly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload