I'm trying to add padding to a textblock and a textbox on the same horizontal alignment (so the text for both starts at the same horizontal location), but it seems to me that the padding for a textblock vs a textbox is off?
I have this code:
<TextBox Text="Test"
BorderThickness="0"
Margin="0"
Padding="12,0,0,0" />
<TextBlock Text="Test"
Margin="0"
Padding="12,0,0,0" />
But on my display, is shows up as this (Stackpanel): 
Grid: 
Esentially, my question is, the padding is the same, so what's up with the horizontal alignment?
Padding represents the distance between the side of the control (which can be the margin) and its content.
Well using your Xaml, I used the Snoop utilty and found out that the Textbox has more inner control. For example border,TextBoxView etc... Refer the below image.

But, in case of TextBlock, there were none. One of the control in Textbox control is TextBoxView, checking out the margin it has 2,0,2,0.

I changed the Margin = -1,0,0,0 and the content padded properly. So the content was padding against the textBoxView. and making the Margin of the textBoxView equal to -1,0,0,0. it appeared correct with TextBlock alignment.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With