This is a migrated thread and some comments may be shown as answers.

GoToPage has no effect

1 Answer 40 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Jacob
Top achievements
Rank 1
Jacob asked on 25 Apr 2016, 08:43 AM

Hello Telerik,

 

I am having an issue when trying to change my document's page when clicking on a ListView item. The page won't change at all.

Here's the code of the sample project I have created specially for this issue:

I also tried the approach in this ticket

http://www.telerik.com/forums/gotopage-issue

but it still won't work in my scenario.

<Window x:Class="TelerikPdf.MainWindow"
        xmlns:local="clr-namespace:TelerikPdf"
        mc:Ignorable="d"
        Title="MainWindow" d:DesignHeight="675" d:DesignWidth="950"
        xmlns:fixed="clr-namespace:Telerik.Windows.Documents.Fixed;assembly=Telerik.Windows.Controls.FixedDocumentViewers"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" >
    <Grid>
        <Grid.Resources>
            <fixed:PdfDocumentSourceValueConverter x:Key="PdfDocumentSourceValueConverter" />
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="13*"/>
        </Grid.RowDefinitions>
 
        <TextBlock Name="LabelDomain" Text="Tutorial " HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" FontSize="18"
                   Grid.Row="0" Grid.Column="0"/>
 
        <Grid Grid.Row="1" Grid.Column="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="7*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
            </Grid.RowDefinitions>
 
            <ListView Grid.Row="0" Grid.Column="0" Name="TutorialItems" SelectionChanged="TutorialItems_SelectionChanged">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <WrapPanel>
                            <TextBlock Text="{Binding}" FontWeight="Bold" />
                        </WrapPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
 
            <Border  Grid.Row="0" Grid.Column="1" BorderBrush="White" BorderThickness="0" Margin="5,0,5,0">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="0.2*"/>
                    </Grid.RowDefinitions>
                    <Border BorderBrush="LightGray" BorderThickness="1" Visibility="Visible" Margin="10,0,10,0">
                        <ScrollViewer Grid.Row="0">
                            <telerik:RadPdfViewer Name="RadPdfViewer" Grid.Row="1" ScaleMode="Normal" />
                        </ScrollViewer>
                    </Border>
                </Grid>
            </Border>
        </Grid>
    </Grid>
</Window>

code behind:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Documents.Fixed.FormatProviders;
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
using Telerik.Windows.Documents.Fixed.Model;
 
namespace TelerikPdf
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            List<string> items = new List<string>();
            items.Add("Introduction");
            items.Add("How to use");
            items.Add("Understanding the customer CSV file");
            items.Add("Understanding the Domain CSV file");
            TutorialItems.ItemsSource = items;
 
            MemoryStream stream = new MemoryStream();
            using (Stream input = File.OpenRead("qwe.pdf"))
            {
                input.CopyTo(stream);
            }
 
            FormatProviderSettings settings = new FormatProviderSettings(ReadingMode.OnDemand);
            PdfFormatProvider provider = new PdfFormatProvider(stream, settings);
            RadFixedDocument doc = provider.Import();
            RadPdfViewer.Document = doc;
        }
 
        private void TutorialItems_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
 
            switch (TutorialItems.SelectedItem.ToString())
            {
                case "Introduction":
                    RadPdfViewer.GoToPage(1);
                    break;
                case "How to use":
                    RadPdfViewer.GoToPage(2);
                    break;
                case "Understanding the customer CSV file":
                    RadPdfViewer.GoToPage(3);
                    break;
 
            }
 
        }
    }
}

 

Best regards!

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 27 Apr 2016, 12:46 PM
Hello Jacob,

ScrollViewer measures its children in Infinity and this leads to disabling the virtualization of RadPdfViewer thus forcing it to load the whole document.

RadPdfViewer comes with a built-in scroll bar, which is used by the GoToPage() method. You could use the default functionality instead of ScrollViewer to avoid the behavior you are currently experiencing as well as unexpected results in the future. The only thing you will need to do is remove the ScrollViewer and keep the PdfViewer directly inside the Border.

Hope this helps.

Regards,
Tanya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
PDFViewer
Asked by
Jacob
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or