I'm trying to create a help system for a software application. The interface is written in WPF. I have an XPS file (produced from a Word doc) that I want to access from the application. The XPS file contains hyperlinks that redirect within the XPS file. I can display the file using the DocumentViewer control, but the hyperlinks don't work. (When I view the same XPS file in the XPS Viewer, the hyperlinks work.) I'm new to WPF, so I may be overlooking something, but I've been trying to make this work for a week now and though I'm learning along the way I'm not getting anywhere with the task at hand. I'd greatly appreciate any help. -Dave
Add the following code in your code behind 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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With