Changing pages orientation

Dec 11, 2011 at 3:26 AM
Edited Dec 11, 2011 at 3:26 AM


Instead of viewing pages vertically, i would like to see them horizontally (with an horizontal scrollbar)

I'm using the DocumentViewer template. I tried to insert something like :

  <StackPanel Orientation="Horizontal" />
but it doesn't work. In fact, the template don't use a listbox structure explicitly...
Thank you for help.


Dec 15, 2011 at 10:46 AM

Have you got a solution please ? I know how to rotate one page from portrait to landscape, but here i need to view all pages with an horizontal scrolling instead of vertical by default.

More, if i could switch between horizontal and vertical, it would be better !

Thank you.

Dec 15, 2011 at 2:40 PM

Use the same technique as in the rotate single page sample ( and then replace the LayoutRotateBehavior with a behavior that binds to a global variable that specifies the rotation angle (similar to how you bind to a global watermark text).

- Koen

Dec 15, 2011 at 3:36 PM

It seems i'm not clear, sorry. I don't want to rotate all the pages, i want to scroll the viewer horizontally : pages are not scrolled up to down but left to right.

I think it's very easy because i did it once during my learning by chance, and i can't reproduce it now (pfff !). As i say above, i may have to place a stackpanel with a bindable orientation, but where can i place this stackpanel in the documentviewer template please ?


Dec 15, 2011 at 3:59 PM

You'll need to set the ItemsControl.ItemsPanel property to a horizontal VirtualizingStackPanel in the DocumentViewer's control template. Something like this works:

<ControlTemplate TargetType="doc:DocumentViewer">
    <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
        <ScrollViewer x:Name="ScrollViewer" Background="Transparent" BorderThickness="0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <ItemsControl x:Name="Pages">
                    <doc:PageVirtualizer />
                <!-- a horizontal items panel-->
                        <VirtualizingStackPanel Orientation="Horizontal" />
                        <Grid Width="{Binding DesiredPageContainerSize.Width}"
                            Height="{Binding DesiredPageContainerSize.Height}">
                            <Border Background="White" BorderBrush="Silver" BorderThickness="1" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Center">
                                <doc:FixedPageViewer FixedPage="{Binding FixedPage}" 
                                                     FixedPageSize="{Binding FixedPageSize}"
                                                     FixedPageError="{Binding FixedPageError}"
                                                     Scale="{Binding DesiredPageScale}">
                                        <doc:FixedPageAdorner Annotations="{Binding TextContainer.Annotations}" Selection="{Binding TextContainer.Selection}" />
                                        <doc:NavigationBehavior TextContainer="{Binding TextContainer}" />
- Koen

Dec 15, 2011 at 4:14 PM

Thnak you very much Koen, it's working great !

So, i think i can leave you in peace now ! LOL

Merry christmas to Silverlight Community, bye.