WPF DocumentViewer GoToPage问题 [英] WPF DocumentViewer GoToPage issue

查看:83
本文介绍了WPF DocumentViewer GoToPage问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我遇到了DocumentViewer GoToPage()方法的问题.
我想在显示控件时将XPS文档导航到特定的页码,但是在初始化窗口期间它将导航到错误的页码.

此外,如果稍后再调用GoToPage(),例如在单击按钮处理程序中-DocumentViewer可以正常工作并导航到正确的页面.

这是一段代码:

Hi All,

I''m facing a problem with DocumentViewer GoToPage() method.
I want to navigate XPS document to specific page number while showing the control, but it navigates to wrong page number during initializing the window.

Moreover, if I call GoToPage() later, e.g. in click button handler - DocumentViewer works fine and navigates to correct page.

Here is a piece of code:

public partial class Window : Window
   {
       private string _XPSpath;

       public Window()
       {
           InitializeComponent();
           _XPSPath = @"C:\DocViewerTest\TestDocument.xps";
           DocViewer.Document = new XpsDocument(_XPSpath, FileAccess.Read).GetFixedDocumentSequence();

           DocViewer.GoToPage(67); // Navigates to 63 page - not OK.
       }

       private void GoToPageButton_Click(object sender, RoutedEventArgs e)
       {
           DocViewer.GoToPage(67); // Navigates to 67 page - OK.
       }

   }



问候,
Anton Kurkov.



Regards,
Anton Kurkov.

推荐答案

我今天遇到了同样的问题,发现了问题所在.将文档保存到xps时,页面大小必须为Letter. Letter为21,59cmx27,94cm,A4为21cmx29,97cm,因此,当您尝试在文档进入屏幕之前到达特定页面时,xps格式为字母,您将在每页中留下"几厘米.使文档可见后,它又回到了您保存文件的页面大小,因此它将正常工作.

我还提出了另一种解决方案,可以跳到页面而不用Letter大小保存文档.


I faced the same problem today and found what was the problem. You have to have your page size as Letter when you save your document to xps. Letter is 21,59cmx27,94cm and A4 is 21cmx29,97cm, so when you try to got to specific page before the document is in screen the xps is in letter format and you will "leave behind" in each page few cm. When the document is rendered visible it is back to the page size you saved the file and thus it will work normally.

I made also another solution to jump to the page without saving the document in Letter size.


DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(50);
dispatcherTimer.Start();

int pagenum = 'your page';

void dispatcherTimer_Tick(object sender, EventArgs e)
{

           Document.GoToPage(pagenum );

           if(pagenum == Document.MasterPageNumber)
               dispatcherTimer.Stop();

}



上面的代码将跳到该页面,直到它是正确的页面为止.

-Tuomas



Above code will jump to the page untill it is the correct page.

- Tuomas


这篇关于WPF DocumentViewer GoToPage问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆