Click here to Skip to main content
15,396,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(google-fu is lacking)

Is it possible to have a textblock with an inline clickable URL ?

I've seen this : Help with Adding a Hyperlink for a Text Block or Text Box[^]

But I need to bind the text before and after.

I'm not sure what is the best approach.

What I have tried:

I've looked at this, and I'm not sure about how to add the hyperlink :

         <MultiBinding StringFormat="{}{0} {1}">
             <Binding Path="UrlMessage2" />
             <Binding Path="UrlMessage"/>  <!-- here should be the hyperlink-->
             <Binding Path="UrlMessage3" />

The example in the link, and I'm not sure how to bind the text before and after the hyperlink :

<TextBlock Name="TextBlockWithHyperlink">
    Text before the hyperlink 
        Text to link to the website
    Text after the hyperlink
Updated 6-Jun-22 23:05pm
Gerry Schmitz 6-Jun-22 23:25pm
Use the TextBlock.Inlines collection. (It's what happens implicitly)

1 solution

Simple enough:
<TextBlock Name="TextBlockWithHyperlink">
    <Run Text="{Binding Path=UrlMessage2, Mode=OneWay}" />
    <Hyperlink NavigateUri="..." RequestNavigate="...">
        <Run Text="{Binding Path=UrlMessage, Mode=OneWay}" />
    <Run Text="{Binding Path=UrlMessage3, Mode=OneWay}" />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900