WPF Document Viewer Update Issues

2.2k views Asked by At

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?

1

There are 1 answers

0
FA Servers On

Update: This issue was caused by working from within a remote desktop session.