Click here to Skip to main content
15,946,988 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 :

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



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 
    <Hyperlink 
         NavigateUri="http://www.google.com/"
        RequestNavigate="Hyperlink_RequestNavigate">
        Text to link to the website
    </Hyperlink>
    Text after the hyperlink
</TextBlock>
Posted
Updated 6-Jun-22 23:05pm
Comments
[no name] 6-Jun-22 23:25pm    
Use the TextBlock.Inlines collection. (It's what happens implicitly)

https://wpf-tutorial.com/basic-controls/the-textblock-control-inline-formatting/

1 solution

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

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