This has to do with the way that a ViewBox
works, in particular with the Canvas
element. The ViewBox
is used to resize child elements, as I'm sure you're aware. There are 2 issues with the Canvas
element:
- The default
Height
andWidth
are 0, which means that theTextBlock
will get all the space. - The
Canvas
element lets you draw outside of its own boundaries, so even if your canvas is tiny or not even visible, you would be allowed to render your grid of numbers.
The quickest solution is to set VerticalAlignment
on the ViewBox
:
<Viewbox VerticalAlignment="Top">
...
</Viewbox>
You could set a Height
on the Canvas, but I think this is less ideal because you don't want to change this dynamically with window resize.