Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set value of hyperlink with WPF by code

Tags:

hyperlink

wpf

I'm using WPF and an Hyperlink control with

    <TextBlock Margin="98,190,116,133.418" FontSize="14">
        <Hyperlink Name="hyperlink" RequestNavigate="Hyperlink_RequestNavigate">
            Click here
        </Hyperlink>
    </TextBlock>

this is working, but I would like to set the "click here" value by code, but I'm unable to find the correct property.

hyperlink.Value ?
hyperlink.Text ?

Thanks in advance for your help

like image 752
Tim Avatar asked Jan 08 '10 10:01

Tim


1 Answers

An alternative answer, which I consider more straightforward than working with the inlines is to put a TextBlock (with x:Name) inside the Hyperlink and then call its Text property in the code behind:

<TextBlock Margin="98,190,116,133.418" FontSize="14">
    <Hyperlink Name="hyperlink" RequestNavigate="Hyperlink_RequestNavigate">
        <TextBlock x:Name="hyperlinkText"/>
    </Hyperlink>
</TextBlock>

Then in code behind you can set the hyperlink's text by calling hyperlinkText.Text, like this:

private void Button_Click(object sender, RoutedEventArgs e)
{
    this.hyperlinkText.Text = "some custom text";
}
like image 82
Hannish Avatar answered Oct 25 '22 16:10

Hannish