How to change hyperlink address in documentviewer

Nov 24, 2011 at 2:09 AM

I have a documentviewer as a UserControl.

 The usercontrol is used in documentviewer to display the xps document on the internet browser. 

I want to change from file tag to internet url in xps viewer.
please help me.
Nov 24, 2011 at 6:38 PM
Edited Nov 24, 2011 at 6:39 PM

There are four steps involved in customizing the hyperlink behavior in Document Toolkit. Hyperlink navigation is implemented using behaviors. The behavior determines the look and feel of the hyperlink and specifies the target URI. The actual link navigation is implemented using another type of behavior (outside the scope of your scenario).

Step 1: Create a custom hyperlink behavior.

A custom hyperlink behavior typically derives from DefaultHyperlinkBehavior. Below show a simple behavior that allows you to intercept the target uri of the link when the left mouse button is pressed.

public class MyHyperlinkBehavior : DefaultHyperlinkBehavior
    protected override void OnAssociatedObjectMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        // TODO: change this.NavigateUri to your own URI
        var uri = this.NavigateUri;

        // raises the LinkClick event on the associated fixed page


Step 2: Create a custom FixedPageWriter

In order to instantiate this behavior for each hyperlink, you need to intercept each call for writing a hyperlink behavior. The XAML for each page is written using a FixedPageWriter. You can create your own FixedPageWriter and intercept any write element and attribute operation. Below a custom PageWriter that writes the custom hyperlink behavior.

Note: you need to make sure the XML namespace matches your behavior.


public class MyFixedPageWriter : FixedPageWriter
    public MyFixedPageWriter(StringBuilder output)
        : base(output)

    public override void WriteHyperlinkBehavior()
        if (WriteStartElement("MyHyperlinkBehavior", "clr-namespace:FirstFloor.Documents.TestApp;assembly=FirstFloor.Documents.TestApp")) {


Step 3: Create a custom LoadFixedPageSettings

In order to actually use the custom FixedPageWriter you need to provide a custom settings class that is used when a page is created. Override the CreatePageWriter method and instantiate your customer page writer.


public class MyFixedPageSettings : LoadFixedPageSettings
    public override FixedPageWriter CreatePageWriter(StringBuilder output)
        return new MyFixedPageWriter(output);


Step 4: Use the custom FixedPageSettings

And finally assign an instance of the custom settings class to the DocumentDataSource.LoadPageSettings property;


this.DataSource.LoadPageSettings = new MyFixedPageSettings();



Hope this helps

- Koen