none
How to center content in block WPF VS2017

    Pertanyaan

  • Can anyone explain me how to center vertically content inside block since it always put in bottom.

    As you can see from picture text is on bottom but vertical align in in center(if i put in vertical align in top does not make any changes), how to make in center? Thank you.

    21 Mei 2018 15:05

Semua Balasan

  • Hi speed258,

    A Textblock itself can't do vertical alignment.

    The best way to do this that I've found is to put the textblock inside a border, so the border does the alignment for you.

        <Border BorderBrush="{x:Null}" Height="50" Width="300">
            <TextBlock TextWrapping="Wrap" Text="Some Text" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>

    Refer: Text vertical alignment in WPF TextBlock

    Note: This forum is discussing and asking questions about the Windows Form and ClickOnce, if you have any questions with WPF, it will be more appropriate to ask your question at Windows Presentation Foundation (WPF) Forum

    Thank you for your understanding.

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    22 Mei 2018 1:14
  • Hi speed258,

    A Textblock itself can't do vertical alignment.

    The best way to do this that I've found is to put the textblock inside a border, so the border does the alignment for you.

        <Border BorderBrush="{x:Null}" Height="50" Width="300">
            <TextBlock TextWrapping="Wrap" Text="Some Text" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>

    Refer: Text vertical alignment in WPF TextBlock

    Note: This forum is discussing and asking questions about the Windows Form and ClickOnce, if you have any questions with WPF, it will be more appropriate to ask your question at Windows Presentation Foundation (WPF) Forum

    Thank you for your understanding.

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Problem is I dont need border, problem is that if i set texblock height equal to font size this happens

    As you can and letter bottom goes hides under something, but top has needed height that letters will be visible normally.

    22 Mei 2018 11:52
  • Hi,

    As I said above, a Textblock itself can't do vertical alignment.

    And if you have more questions about WPF, it will be more appropriate to ask your question at Windows Presentation Foundation (WPF) Forum

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    23 Mei 2018 2:19