Prevent Scrollviewer from Scrolling just before printing?

末鹿安然 提交于 2019-12-13 05:54:29

问题


I'm trying to print my visual into a multipage xps. The first page is working but the others are left blank.

Dim xP As Integer = 0
Dim yP As Integer = 0
xP = Math.Ceiling(WorkFlowCanvas.Width / pageWidth)
yP = Math.Ceiling(WorkFlowCanvas.Height / pageHeight)
Dim collator = writer.CreateVisualsCollator()
collator.BeginBatchWrite()
For y = 1 To yP
    For x = 1 To xP
        Dim o As New Canvas
        o = New CanvasCreator().GenerateCanvas()
        Dim sv As New ScrollViewer
        sv.Height = 1200
        sv.Width = 800
        sv.Content = o
        sv.ScrollToHorizontalOffset(x - 1 * sv.Width)
        sv.ScrollToVerticalOffset(y - 1 * sv.Height)
        sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled
        sv.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled
        collator.Write(sv)
    Next
Next
collator.Write(Me)
collator.EndBatchWrite()

By making the visual in xaml and printing it I noticed the scrollviewer always scrolls the content up before writing it(the scrollbars don't move). Is there a way to 'freeze' the scrollviewer?


回答1:


This solution is hacky but it seems to work for me.

            sv.IsEnabled = False
            collator.Write(sv)
            sv.IsEnabled = True

You can stil answer if you know why I have to do this.



来源:https://stackoverflow.com/questions/10981996/prevent-scrollviewer-from-scrolling-just-before-printing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!