TextBlock vs TextBox Padding - XAML WPF
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?
c# wpf xaml
add a comment |
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?
c# wpf xaml
Not sure I follow what you're asking. You show two things that I would expect to see in terms of vertical placement. But it seems as if you're really questioning the horizontal placement. If that's not the case, then perhaps you need to be a bit more explicit with your question.
– DonBoitnott
Nov 13 '18 at 19:53
That was totally my bad. I reworded my question. I realized I used "vertical alignment" when I meant "horizontal alignment" the entire time. I hope it makes more sense now!
– Thomas Zhang
Nov 13 '18 at 21:39
You may have more luck with a Label instead of TextBlock, as the latter doesn't really have content.
– Joey
Nov 13 '18 at 21:41
add a comment |
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?
c# wpf xaml
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?
c# wpf xaml
c# wpf xaml
edited Nov 13 '18 at 21:43
Thomas Zhang
asked Nov 13 '18 at 18:03
Thomas ZhangThomas Zhang
11010
11010
Not sure I follow what you're asking. You show two things that I would expect to see in terms of vertical placement. But it seems as if you're really questioning the horizontal placement. If that's not the case, then perhaps you need to be a bit more explicit with your question.
– DonBoitnott
Nov 13 '18 at 19:53
That was totally my bad. I reworded my question. I realized I used "vertical alignment" when I meant "horizontal alignment" the entire time. I hope it makes more sense now!
– Thomas Zhang
Nov 13 '18 at 21:39
You may have more luck with a Label instead of TextBlock, as the latter doesn't really have content.
– Joey
Nov 13 '18 at 21:41
add a comment |
Not sure I follow what you're asking. You show two things that I would expect to see in terms of vertical placement. But it seems as if you're really questioning the horizontal placement. If that's not the case, then perhaps you need to be a bit more explicit with your question.
– DonBoitnott
Nov 13 '18 at 19:53
That was totally my bad. I reworded my question. I realized I used "vertical alignment" when I meant "horizontal alignment" the entire time. I hope it makes more sense now!
– Thomas Zhang
Nov 13 '18 at 21:39
You may have more luck with a Label instead of TextBlock, as the latter doesn't really have content.
– Joey
Nov 13 '18 at 21:41
Not sure I follow what you're asking. You show two things that I would expect to see in terms of vertical placement. But it seems as if you're really questioning the horizontal placement. If that's not the case, then perhaps you need to be a bit more explicit with your question.
– DonBoitnott
Nov 13 '18 at 19:53
Not sure I follow what you're asking. You show two things that I would expect to see in terms of vertical placement. But it seems as if you're really questioning the horizontal placement. If that's not the case, then perhaps you need to be a bit more explicit with your question.
– DonBoitnott
Nov 13 '18 at 19:53
That was totally my bad. I reworded my question. I realized I used "vertical alignment" when I meant "horizontal alignment" the entire time. I hope it makes more sense now!
– Thomas Zhang
Nov 13 '18 at 21:39
That was totally my bad. I reworded my question. I realized I used "vertical alignment" when I meant "horizontal alignment" the entire time. I hope it makes more sense now!
– Thomas Zhang
Nov 13 '18 at 21:39
You may have more luck with a Label instead of TextBlock, as the latter doesn't really have content.
– Joey
Nov 13 '18 at 21:41
You may have more luck with a Label instead of TextBlock, as the latter doesn't really have content.
– Joey
Nov 13 '18 at 21:41
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287014%2ftextblock-vs-textbox-padding-xaml-wpf%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 13 '18 at 20:18
Satish PaiSatish Pai
7841510
7841510
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287014%2ftextblock-vs-textbox-padding-xaml-wpf%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Not sure I follow what you're asking. You show two things that I would expect to see in terms of vertical placement. But it seems as if you're really questioning the horizontal placement. If that's not the case, then perhaps you need to be a bit more explicit with your question.
– DonBoitnott
Nov 13 '18 at 19:53
That was totally my bad. I reworded my question. I realized I used "vertical alignment" when I meant "horizontal alignment" the entire time. I hope it makes more sense now!
– Thomas Zhang
Nov 13 '18 at 21:39
You may have more luck with a Label instead of TextBlock, as the latter doesn't really have content.
– Joey
Nov 13 '18 at 21:41