Can hyperlinks work in XPS files displayed in WPF controls?

I am trying to create a help system for a software application. The interface is written in WPF. I have an XPS file (derived from a Word document) that I want to get from an application. The XPS file contains hyperlinks that redirect to the XPS file. I can display the file using the DocumentViewer control, but the hyperlinks do not work. (When I look at the same XPS file in the XPS viewer, hyperlinks work.) I am new to WPF, so I can ignore something, but I tried to do this work for a week, I learned along the way when I don’t leave with this task. I would really appreciate any help. -Dave

+4
source share
2 answers

Add the following code to your code to handle the hyperlinks manually:

public MainWindow() { xpsViewer.AddHandler(Hyperlink.RequestNavigateEvent, new RequestNavigateEventHandler(OnRequestNavigate)); } private void OnRequestNavigate(object sender, RequestNavigateEventArgs e) { // URI contains the page number (e.Uri = "...#PG_7_LNK_2") int pageNumber; if (int.TryParse(Regex.Match(e.Uri.ToString(), @"(?<=PG_)[0-9]+").Value, out pageNumber)) { xpsViewer.GoToPage(pageNumber); } } 
+1
source

I know this is an old question, but for anyone looking for an answer, I think the problem is that the hyperlinks only work inside the navigation container - Frame or NavigationWindow, so you have to place the DocumentViewer in the navigation container.

0
source

Source: https://habr.com/ru/post/1333613/


All Articles