Set hyperlink value using WPF by code

I am using WPF and a hyperlink control with

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

this works, but I would like to set the value "click here" by code, but I can not find the correct property.

hyperlink.Value ?
hyperlink.Text ?

Thank you in advance for your help.

+3
source share
3 answers

An alternative answer, which I find simpler than working with inline strings, is to put TextBlock(c x:Name) inside Hyperlinkand then call its property Textin the code behind:

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

, hyperlinkText.Text, :

private void Button_Click(object sender, RoutedEventArgs e)
{
    this.hyperlinkText.Text = "some custom text";
}
+7

Inlines :

hyperlink.Inlines.Clear();
hyperlink.Inlines.Add("Your text here");
+3
source

Source: https://habr.com/ru/post/1727748/


All Articles