TextBlock vs TextBox Padding - XAML WPF










0















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): stackpanel



Grid: grid



Esentially, my question is, the padding is the same, so what's up with the horizontal alignment?










share|improve this question
























  • 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















0















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): stackpanel



Grid: grid



Esentially, my question is, the padding is the same, so what's up with the horizontal alignment?










share|improve this question
























  • 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













0












0








0








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): stackpanel



Grid: grid



Esentially, my question is, the padding is the same, so what's up with the horizontal alignment?










share|improve this question
















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): stackpanel



Grid: grid



Esentially, my question is, the padding is the same, so what's up with the horizontal alignment?







c# wpf xaml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 21:43







Thomas Zhang

















asked Nov 13 '18 at 18:03









Thomas ZhangThomas Zhang

10810




10810












  • 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











  • 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












1 Answer
1






active

oldest

votes


















1














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.
enter image description here



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.



enter image description here



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.



enter image description here






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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.
    enter image description here



    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.



    enter image description here



    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.



    enter image description here






    share|improve this answer



























      1














      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.
      enter image description here



      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.



      enter image description here



      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.



      enter image description here






      share|improve this answer

























        1












        1








        1







        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.
        enter image description here



        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.



        enter image description here



        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.



        enter image description here






        share|improve this answer













        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.
        enter image description here



        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.



        enter image description here



        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.



        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 20:18









        Satish PaiSatish Pai

        7841510




        7841510



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3