1

I have a very simple screen which shows some content and a hyperlink. As the hyperlink is spread over multiline I can't use WPF button as it would move the whole link into a new line which is not acceptable by the client.

This is a Caliburn micro MVVM application and I handle the process of opening the link in my method in the view model. I don't want to use code-behind thus need to bind the RequestNavigate event of the hyperlink.

Code for rich textbox is

 <RichTextBox FontSize="13"  BorderThickness="0" IsDocumentEnabled="True" IsReadOnly="True" Block.TextAlignment="Center"  Width="270">
        <FlowDocument>
            <Paragraph>
                Download Failed. Please
                <Bold>check your connection and try again or</Bold>
                <Hyperlink >contact your provider</Hyperlink>
            </Paragraph>
        </FlowDocument>
    </RichTextBox>

Output is

enter image description here

Manvinder
  • 4,495
  • 16
  • 53
  • 100

1 Answers1

1

Hyperlink implements ICommandSource interface, so you can use it's Command property to bind to a Command on ViewModel, just like you would with a Button.

<Hyperlink Command="{Binding MyNavigationRequestedCommand}">contact your provider</Hyperlink>

I guess you're familiar with implementation since you mentioned you would use a Button, but here is a link to an explanation here on SO. If you need to handle RequestNavigate event specifically, you can use EventTrigger + InvokeCommandAction from System.Widnows.Interactivityas described here.

djomlastic
  • 422
  • 2
  • 6