Night Walker
Night Walker

Reputation: 21260

Allignment with Hyperlink text

Why the text in the hyperlink is vertical aligned to the top and not goes to the same line as the label . Any idea why ?

<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="5">
    <Label   TextElement.FontSize="18" 
             FontWeight="Bold"
             HorizontalAlignment="Left"
             VerticalAlignment="Top"
             Name="LDOTextFilelable"
             Content="LDO Text File:"
             BorderThickness="0"/>



    <TextBlock Height="39" TextElement.FontSize="18" FontFamily="Verdana"  VerticalAlignment="Bottom"
               Name="LDOTextFilelink" Padding="5,0,0,0" >
        <Hyperlink Command="{Binding Path= SaveChangesCommand}" >
                    <TextBlock Text="{Binding Path=LdoFilePath}" Height="39"  VerticalAlignment="Bottom"/>
        </Hyperlink>
    </TextBlock>

</StackPanel>

enter image description here

Thanks for help.

Upvotes: 1

Views: 1399

Answers (2)

SINGULARITY
SINGULARITY

Reputation: 1212

The default padding for a label in WPF is 5 in every direction.

With that knowledge we can apply a padding of 5 to the TextBlock that surrounds the hyperlink.

For example:

<StackPanel Orientation="Horizontal">
    <Label FontWeight="Bold" Content="Home Page:"/>
    <TextBlock Padding="5">
        <Hyperlink NavigateUri="{Binding WebsiteUrl}">URL TEXT</Hyperlink>
    </TextBlock>
</StackPanel>

Upvotes: 0

Vlad
Vlad

Reputation: 35584

The preferred way to place hyperlinks in the text is following:

<TextBlock Name="TextBlockWithHyperlink">
    <Run FontWeight="Bold">LDO Text File: </Run>
    <Hyperlink Command="{Binding Path= SaveChangesCommand}">
        <TextBlock FontFamily="Verdana" Text="{Binding Path=LdoFilePath}"/>
    </Hyperlink>
</TextBlock>

This way you'll have no problems with alignment.

In WPF 4.0 you can replace the inner TextBlock with a simple Run.

Upvotes: 4

Related Questions