Kumar
Kumar

Reputation: 11369

How to get the text property of a hyperlink

There is no .Text property on hyperlink in WPF

looking to get the text in the click event and the only way so far is

Run r = hyperlink.Inlines.First() as Run;
gotText( r.Text );

Somehow this seems rather convoluted given that hyperlinks do have a text/content

Or is this an oversight or perhaps there's a better reason why this property does not exist ?

Upvotes: 1

Views: 144

Answers (2)

Kavet Kerek
Kavet Kerek

Reputation: 1315

This is because the Hyperlink control is derived from the TextElement Class. Specifically it is supposed to be a control that is able to sit within flow content. While one might initially view the control as something simple like a TextBox, but in order for the Hyperlink control to fit nicely within FlowContent it needs to have a similar structure to other flow content elements.

For more on FlowContent take a look at this.

Upvotes: 0

Justin R.
Justin R.

Reputation: 24061

I believe that this is because a hyperlink can potentially have multiple runs of text.

Upvotes: 1

Related Questions