1

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.

2 Answers 2

4

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.

1
  • Thanks for the tip . How I can give in this way different FontWeight for my "LDO Text File:" and for the "LdoFilePath" thanks . Oct 22, 2011 at 10:53
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.