Changing pages orientation

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

Hello,

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 :

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

 

Dec 15, 2011 at 11: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.

Coordinator
Dec 15, 2011 at 3:40 PM

Use the same technique as in the rotate single page sample (http://documenttoolkit.codeplex.com/SourceControl/changeset/view/83547#1905147) 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 4: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 ?

 

Coordinator
Dec 15, 2011 at 4: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">
                <i:Interaction.Behaviors>
                    <doc:PageVirtualizer />
                </i:Interaction.Behaviors>
                <!-- a horizontal items panel-->
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <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}">
                                    <i:Interaction.Behaviors>
                                        <doc:FixedPageAdorner Annotations="{Binding TextContainer.Annotations}" Selection="{Binding TextContainer.Selection}" />
                                        <doc:NavigationBehavior TextContainer="{Binding TextContainer}" />
                                    </i:Interaction.Behaviors>
                                </doc:FixedPageViewer>
                            </Border>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </Border>
</ControlTemplate>
- Koen

Dec 15, 2011 at 5: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.