How can I center align text with hyperlinks in it?

Stout 286 Reputation points
2021-02-25T20:48:51.047+00:00

Hi. How can I center align text with hyperlinks in it?

I need to have the some text below, and with the XAML I got it's currently not centered. In fact, Horizontal Alignment does not seem to have any effect. Hyperlinks are working fine, however.

This is inside a grid with 2 columns, and I need the ColumnSpan to be 2.

Thanks.

"By clicking Sign In, you agree to our [HYPERLINK: Privacy Policy] and [HYPERLINK: Terms of Use.]"

    <TextBlock Grid.Row="3" Grid.ColumnSpan="2" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" FontSize="18px">
        <Run Text="By clicking Sign In, you agree to our " /> 
        <Hyperlink NavigateUri="https://www.my-company-website.com/privacy-policy/" RequestNavigate="Hyperlink_RequestNavigate">
            Privacy Policy
        </Hyperlink>
        <Run Text=" and "/>
        <Hyperlink NavigateUri="https://www.my-company-website.com/terms-and-conditions/" RequestNavigate="Hyperlink_RequestNavigate">
            Terms of Use.
        </Hyperlink>
    </TextBlock>
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,701 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
778 questions
0 comments No comments
{count} votes

Accepted answer
  1. Stout 286 Reputation points
    2021-02-25T23:44:51.837+00:00

    Someone just told me that HorizontalAlignment is for the entire TextBlock control, whereas TextAlignment is for the actual text content. So:

    <TextBlock TextAlignment="Center" ...
    
    0 comments No comments

0 additional answers

Sort by: Most helpful