For self-generated xps files with custom hyperlinks, you need to add RequestNavigate to the hyperlinks. Then you can navigate the hyperlink to your target file.
The code of the project that generates the xps file:
Imports System.IO
Imports System.IO.Packaging
Imports System.Windows.Xps.Packaging
Imports System.Windows.Xps.Serialization
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub Hyperlink_RequestNavigate(ByVal sender As Object, ByVal e As System.Windows.Navigation.RequestNavigateEventArgs)
Process.Start(New ProcessStartInfo(e.Uri.AbsoluteUri))
e.Handled = True
End Sub
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim myParagraph As Paragraph = New Paragraph()
Dim run1 As Run = New Run("mylittlecustomprotocol://tonsandtonsofencryptedgarbagehere")
Dim h1 As Hyperlink = New Hyperlink(run1)
h1.NavigateUri = New Uri("mylittlecustomprotocol://tonsandtonsofencryptedgarbagehere")
AddHandler h1.RequestNavigate, AddressOf Hyperlink_RequestNavigate
myParagraph.Inlines.Add(h1)
Dim myFlowDocument As FlowDocument = New FlowDocument()
myFlowDocument.Blocks.Add(myParagraph)
Me.Content = myFlowDocument
Dim ftx As FlowToXps = New FlowToXps()
ftx.SaveAsXps("C:\\...\\tt.xps", myFlowDocument)
End Sub
End Class
Public Class FlowToXps
Public Sub SaveAsXps(ByVal path As String, ByVal document As FlowDocument)
Using package As Package = Package.Open(path, FileMode.Create)
Using xpsDoc = New XpsDocument(package, CompressionOption.Maximum)
Dim xpsSm = New XpsSerializationManager(New XpsPackagingPolicy(xpsDoc), False)
Dim dp As DocumentPaginator = (CType(document, IDocumentPaginatorSource)).DocumentPaginator
xpsSm.SaveAsXaml(dp)
End Using
End Using
End Sub
End Class
The code of the project that reads the xps file:
Imports System.IO
Imports System.Windows.Xps.Packaging
Partial Public Class MainWindow
Public Sub New()
InitializeComponent()
Dim ogXps = "C:\\...\\tt.xps"
Dim xpsDoc As XpsDocument = New XpsDocument(ogXps, FileAccess.Read)
Dim seqDoc As FixedDocumentSequence = xpsDoc.GetFixedDocumentSequence()
dv.Document = seqDoc
End Sub
End Class
The result is shown in the figure: