Search code examples
wpfwpf-controlstextblock

How to show text at the center of a TextBlock without changing its width?


I was thinking is there any way to show the texts at the center of a TextBlock without changing its width? I've already tried this:

  <TextBlock HorizontalAlignment="Center"></TextBlock>

As i said it changes width of the TextBlock,but in some cases i need to Stretch TextBlock to it's parent,assume that the TextBlock has border so i need to make it Stretch to it's parent. Actually i need to do this on the TextBlock that is placed inside the DataGridTextColumn,so please don't give answers that i can't use!like using other controls or something like that!


Solution

  • TextBlock.TextAlignment="Center"