Question

I am trying to open an xps document in wpf with vb as a fixed document with documentviewer, then navigate to a bookmark/link within the document. I have unpacked the xps and found the available links in DocStucture.struct, but I don't know how to tell the documentviewer to go to the link's location. The documentviewer is contained within a Frame in a window and I can click on a link in the document's table of contents to the different links. The purpose is to allow the end user to open the document to a specific location when he/she pushes a button (the document is a user guide).

Can someone explain how to do this? Thanks!

edit: I have tried packing the link into a uri, however I can only figure out how to make the frame navigate to a uri not the documentviewer:

class for the window that contains the user manual:

Partial Public Class UserManual
    Private Sub DocViewer_Loaded(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
        Dim documentName As String = "@.\User Manual.xps"
        Dim xpsDoc As XpsDocument
        xpsDoc = New XpsDocument(documentName, IO.FileAccess.Read)  
        DocViewer.Document = xpsDoc.GetFixedDocumentSequence
    End Sub
    Public Sub New()
        MyBase.New()
        Me.InitializeComponent()
    End Sub
End Class

in the main window from which the user manual will be opened:

Private Sub Button_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim UserManualWindow As UserManual = New UserManual
    UserManualWindow.Show()
    Dim uri = New Uri("pack://file:,,,/User Manual.xps#PG_8_LNK_94")
    UserManualWindow.DocFrame.Navigate(uri)
End Sub

This doesn't work. The frame just shows the text of the uri. I can't find a similar method of the documentviewer. The gotopage method only takes in a page number, not a link.

Was it helpful?

Solution

So I managed to work through it and learned that I was close. Instead of commanding the frame to navigate to the uri, I just needed to set the frame's source:

UserManualWindow.DocFrame.Source = uri

Now the frame updates to the correct fragment within the xps document.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top