Reputation: 13992
I have a Hyperlink inside a RichTextBlock
. I'm using MVVM and I would like to bind it to a Command
. How do I do it?
<RichTextBlock>
<Paragraph>
<Run Text="This is " />
<Hyperlink>
<Hyperlink.Inlines>
<Run Text="a link" />
</Hyperlink.Inlines>
</Hyperlink>
</Paragraph>
</RichTextBlock>
Upvotes: 0
Views: 685
Reputation: 3970
You can add do this using the InlineUIContainer
and then adding an HyperlinkButton
.
<RichTextBlock>
<Paragraph>
<Run Text="This is" />
<InlineUIContainer >
<HyperlinkButton Margin="0,0,0,-10"
Command="{Binding LinkCommand}">
a link
</HyperlinkButton>
</InlineUIContainer>
<Run Text="and this is some additional text" />
</Paragraph>
</RichTextBlock>
You can also use a binding for the link text:
<HyperlinkButton Margin="0,0,0,-10"
Command="{Binding myCommand}"
Content="{Binding LinkText}">
</HyperlinkButton>
I have used the negative margin to align the link with the other text content.
Upvotes: 2