WPF 文档查看器更新问题
经过长时间的战斗,使用 WPF 中的 documentViewer 实现固定文档的文档轮换,我终于设法让它与下面的代码一起工作:
//Increment Rotation
if (Rotation == 270)
Rotation = 0;
else
Rotation += 90;
FixedDocument document = (FixedDocument)docViewer.Document;
foreach (PageContent page in document.Pages)
{
//Create New Size
Size newSize = new Size(page.Child.Height, page.Child.Width);
//Adjust Size
page.Child.Height = newSize.Height;
page.Child.Width = newSize.Width;
page.Height = newSize.Height;
page.Width = newSize.Width;
//Create Transform
TransformGroup pageTransform = new TransformGroup();
pageTransform.Children.Add(new RotateTransform(Rotation));
//Set Transform Shift
if (Rotation == 90)
pageTransform.Children.Add(new TranslateTransform(newSize.Width, 0));
if (Rotation == 180)
pageTransform.Children.Add(new TranslateTransform(newSize.Width, newSize.Height));
if (Rotation == 270)
pageTransform.Children.Add(new TranslateTransform(0, newSize.Height));
page.Child.RenderTransform = pageTransform;
//Update
page.Measure(newSize);
page.Arrange(new Rect(newSize));
page.UpdateLayout();
}
docViewer.Document = null;
docViewer.InvalidateVisual();
docViewer.Document = document;
docViewer.InvalidateVisual();
docViewer.UpdateLayout();
问题是,当您查看文档时,第一页(或开始查看时看到的任何页面)旋转)不会完全刷新。 (页面大小发生变化,但转换不会生效。)直到您滚动到视图之外然后返回,然后一切都很好。我该如何解决这个问题?
After a lenghtly battle implementing document rotation for fixed documents using the documentViewer in WPF I finally manged to get it working with the code below:
//Increment Rotation
if (Rotation == 270)
Rotation = 0;
else
Rotation += 90;
FixedDocument document = (FixedDocument)docViewer.Document;
foreach (PageContent page in document.Pages)
{
//Create New Size
Size newSize = new Size(page.Child.Height, page.Child.Width);
//Adjust Size
page.Child.Height = newSize.Height;
page.Child.Width = newSize.Width;
page.Height = newSize.Height;
page.Width = newSize.Width;
//Create Transform
TransformGroup pageTransform = new TransformGroup();
pageTransform.Children.Add(new RotateTransform(Rotation));
//Set Transform Shift
if (Rotation == 90)
pageTransform.Children.Add(new TranslateTransform(newSize.Width, 0));
if (Rotation == 180)
pageTransform.Children.Add(new TranslateTransform(newSize.Width, newSize.Height));
if (Rotation == 270)
pageTransform.Children.Add(new TranslateTransform(0, newSize.Height));
page.Child.RenderTransform = pageTransform;
//Update
page.Measure(newSize);
page.Arrange(new Rect(newSize));
page.UpdateLayout();
}
docViewer.Document = null;
docViewer.InvalidateVisual();
docViewer.Document = document;
docViewer.InvalidateVisual();
docViewer.UpdateLayout();
The problem is that when you view the document the first page (or whatever page was in view when you began the rotation) doesnt get refreshed entirely. (The page size changes but the transforms dont take effect.) Until you scroll out of view then back and then everything is fine. How do I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:此问题是由于在远程桌面会话中工作引起的。
Update: This issue was caused by working from within a remote desktop session.