Hi,
I'm using the last version of telerik and I was trying to integrate the RadPdfViewerToolBar into RadPdfViewer
This is my code
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
telerik:RadPdfViewerToolBar
RadPdfViewer
=
"{Binding ElementName=pdfViewer, Mode=OneTime}"
/>
<
telerik:RadPdfViewer
Grid.Row
=
"2"
x:Name
=
"pdfViewer"
DataContext
=
"{Binding CommandDescriptors, ElementName=pdfViewer}"
RenderOptions.BitmapScalingMode
=
"HighQuality"
/>
<
telerik:RadPdfViewerToolBar
/>
</
Grid
>
I populate the pdfViewer on datacontext change
private
void
RootElement_DataContextChanged(
object
sender, DependencyPropertyChangedEventArgs e)
{
if
(e.NewValue != e.OldValue)
{
pdfViewer.DocumentSource =
new
PdfDocumentSource(
new
Uri(e.NewValue.ToString()));
}
}
As shown on the attachment, the toolbar it seems not related to the pdfviewer.
Another question. Is it possible to specify a page number when I open the pdf? Something like GotoPage xy
Thank you
5 Answers, 1 is accepted
Thank you for your questions.
It seems to me that what is causing your issue is the additional RadPdfViewerToolBar at the very bottom of your code which is not associated with the RadPdfViewer. It is positioned on the first row of the grid and it covers the functioning RadPdfViewerToolBar. If you delete the second toolbar everything should function properly.
As for your second question, there is a property of the RadPdfViewer called CurrentPageNumber which you can use to achieve this. Perhaps it would be best to use the DocumentChanged event of the viewer to set the current page as it would ensure that the document is loaded.
private
void
PdfViewer_DocumentChanged(
object
sender, DocumentChangedEventArgs e)
{
this
.pdfViewer.CurrentPageNumber = 2;
}
Regards,
Anna
Progress Telerik
Hi Anna,
You're right! I didn't saw the double toolbar.. my mistake..
As for my second question I still have the issue on first load.
I have N buttons on a grid, one on each row. When I press one of them I call the PdfViewerUserControl and I populate the DataContext with my object DocumentsAndScannedDocument. This object contain the pdf and the page that I want to go.
The problem is that the first time that I press any button pdfviewer always go to the 1st page. After that it works fine.
Button Event
private
void
ViewDocumentButton_Click(
object
sender, RoutedEventArgs e)
{
RadButton button = sender
as
RadButton;
DocumentsAndScannedDocument scannedDocument = button.DataContext
as
DocumentsAndScannedDocument;
using
(
new
WpfWaitCursor())
{
PdfViewerUserControl.DataContext = scannedDocument;
previewRadDocumentPane.Visibility = Visibility.Visible;
previewRadDocumentPane.IsPinned =
true
;
}
}
PdfViewerUserControl.xaml
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
telerik:RadPdfViewerToolBar
x:Name
=
"pdfViewerToolBar"
RadPdfViewer
=
"{Binding ElementName=pdfViewer, Mode=OneTime}"
/>
<
telerik:RadPdfViewer
Grid.Row
=
"2"
x:Name
=
"pdfViewer"
DataContext
=
"{Binding CommandDescriptors, ElementName=pdfViewer}"
RenderOptions.BitmapScalingMode
=
"HighQuality"
DocumentChanged
=
"pdfViewer_DocumentChanged"
/>
</
Grid
>
Code behind
private
void
RootElement_DataContextChanged(
object
sender, DependencyPropertyChangedEventArgs e)
{
if
(e.NewValue != e.OldValue)
{
DocumentsAndScannedDocument scannedDocument = e.NewValue
as
DocumentsAndScannedDocument;
pdfViewer.DocumentSource =
new
PdfDocumentSource(
new
Uri(scannedDocument.OriginalFilename));
}
}
private
void
pdfViewer_DocumentChanged(
object
sender, DocumentChangedEventArgs e)
{
DocumentsAndScannedDocument scannedDocument =
this
.DataContext
as
DocumentsAndScannedDocument;
this
.pdfViewer.CurrentPageNumber = scannedDocument.Page;
}
Thank you
Using the provided code I've setup a sample project but I could not reproduce the issue with the initially set page number. In the project, I am using a single button that, when clicked, resets the RadPdfViewer DocumentSource and CurrentPageNumber. It works as expected each time (including the first time). You can find the project attached.
Please take a look and let us know whether it works at your side too. If not, I will kindly ask you to open a new ticket and attach either your project or this one(modified to demonstrate the issue) so we can get a better understanding of your scenario and assist you further.
Regards,
Polya
Progress Telerik
Hi,
try to change your xaml like this:
<
telerik:RadDocking
>
<
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
>
<
telerik:RadPaneGroup
>
<
telerik:RadPane
Header
=
"Documents Loaded"
CanUserClose
=
"False"
>
<
telerik:RadButton
Click
=
"ViewDocumentButton_Click"
Content
=
"Load sample document"
DataContext
=
"{Binding ButtonDataContext}"
/>
</
telerik:RadPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
InitialPosition
=
"DockedRight"
Width
=
"550"
>
<
telerik:RadPaneGroup
>
<
telerik:RadDocumentPane
x:Name
=
"previewRadDocumentPane"
Title
=
"Preview"
IsPinned
=
"False"
CanDockInDocumentHost
=
"False"
CanUserClose
=
"False"
CanFloat
=
"True"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
telerik:RadPdfViewerToolBar
Grid.Row
=
"1"
x:Name
=
"pdfViewerToolBar"
RadPdfViewer
=
"{Binding ElementName=pdfViewer, Mode=OneTime}"
/>
<
telerik:RadPdfViewer
Grid.Row
=
"2"
x:Name
=
"pdfViewer"
DataContext
=
"{Binding CommandDescriptors, ElementName=pdfViewer}"
RenderOptions.BitmapScalingMode
=
"HighQuality"
DocumentChanged
=
"pdfViewer_DocumentChanged"
/>
</
Grid
>
</
telerik:RadDocumentPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking
>
and pdfViewer_DocumentChanged like this
private
void
pdfViewer_DocumentChanged(
object
sender, DocumentChangedEventArgs e)
{
previewRadDocumentPane.Visibility = Visibility.Visible;
previewRadDocumentPane.IsPinned =
true
;
DocumentsAndScannedDocument scannedDocument =
this
.DataContext
as
DocumentsAndScannedDocument;
this
.pdfViewer.CurrentPageNumber = scannedDocument.Page;
}
The default value of RadPane's IsPinned property is true. If it is set to false in xaml when the RadDocking is loaded an unpin animation is played and the content of the RadPane is moved to a popup which is then hidden.
That said, we recommend setting the IsPinned when you wish to manually hide a RadPane, but not as an initial state. If in the example the IsPinned of the Preview RadPane is not set to false initially everything works as expected.
I recommend setting the IsPinned to false after the InitializeComponent(), when the template is applied, of the UserControl. I've modified the project to demonstrate this approach. Please find it attached.
Regards,
Polya
Progress Telerik