Set value of hyperlink with WPF by code
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";}