how to make wpf textblock autosize
See the question and my original answer on StackOverflowBy default, elements have an HorizontalAligment
and VerticalAligment
properties that are set to Stretch
, so they will adapt to their parent.
But if you set these to Center
, the element will keep its natural size, so you can test this (or setting properties using code instead of XAML):
<TextBlock Text="This is my text"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
It worked in my case, maybe not in every case.