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

PDFViewer for different documents without Open button (MVVM)

6 Answers 65 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 12 May 2019, 05:09 PM

Hello, Telerik Support Team!

I am quite new with Telerik WPF components, so do not throw bricks at me if I ask some obvious questions.

So I try to create an application with PDFViewer. I have some PDF documents with their addresses in different places in some PC. These addresses are bounded to some controls (f.e. buttons). So I would like to click on the button for document 1 - and document 1 appears on screen, then I click on button for document 2 - and document 2 appears on screen and so on.

So, I red the previous topic (https://www.telerik.com/forums/radpdfviewer-document-binding-in-mvvm) - so I tried to fill my DocumentSource property in ModelView constructor and it works normally and PDFViewer shows document.

However, when I tried to bind some relaycommand, which changed DocumentSource property, to some button - after I clicked on this button in some unexplainable (just for me) reason document didn´t changed (however relaycommand was executed) and first document remains in PDFViewer on the screen.

Here is my method (from ModelView), which changed DocumentSource property:

---------------------------------------------------------------------------------------------------

        private void LoadAnotherPDFDocument()
        {
            MemoryStream stream1 = new MemoryStream();
            using (Stream input1 = File.OpenRead(AnotherPdfFilePath))
            {
                input1.CopyTo(stream1);
            }
            FormatProviderSettings settings1 = new FormatProviderSettings(ReadingMode.AllAtOnce);            
            PDFDocument = new PdfDocumentSource(stream1);
        }

---------------------------------------------------------------------------------------------------

 

And here is my DocumentSourceProperty:

---------------------------------------------------------------------------------------------------

PdfDocumentSource _PDFDocument;
        public PdfDocumentSource PDFDocument
        {
            get { return _PDFDocument; }
            set
            {
                if (_PDFDocument != value)
                {
                    _PDFDocument = value;
                    OnPropertyChanged(nameof(PDFDocument));
                    OnPropertyChanged(nameof(MyProperty));
                }
            }

        }

---------------------------------------------------------------------------------------------------

And DocumentSource from xaml is really bounded to DocumentSource property:

---------------------------------------------------------------------------------------------------

 <telerik:RadPdfViewer x:Name="pdfViewer" 
                                  telerik:RadPdfViewerAttachedComponents.RegisterSignSignatureDialog="True" 
                                  telerik:RadPdfViewerAttachedComponents.RegisterFindDialog="True" 
                                  Grid.Row="2" 
                                  telerik:RadPdfViewerAttachedComponents.RegisterSignaturePropertiesDialog="True" 
                                  telerik:RadPdfViewerAttachedComponents.RegisterContextMenu="True"
                                  DocumentSource="{Binding PDFDocument,Mode=TwoWay}"/>

---------------------------------------------------------------------------------------------------

So, can you help me? How can I open different documents without clicking on open button (I have only predifined documents in my app so I dont want to allow user to browse in hard disk).

 

Thank you in addition!

 

Best regards, 

Alexander Panteleev

6 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 15 May 2019, 04:55 PM
Hi Alexander,

After taking a look I couldn't find any obvious problems with the code you have provided. The issue you are encountering can be related to the binding of the DocumentSource property. Please, find attached a sample project demonstrating the approach of loading PDF documents using two buttons and MVVM.

I hope this helps you achieve the desired result.

Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alexander
Top achievements
Rank 1
answered on 20 May 2019, 11:58 AM

Hi,Georgi

Thank you so much for your example - it works and simple to understand. However... I cant understand, why pdfViewer in my project doesn't work like pdfViewer in your project.

I tried to create simple project, which would be a copy of your project - just pdfViewer and couple of buttons. So, I really did a copy of your project - but it doesn´t work. I mean after I click on button - document in pdfViewer stays the same. I really tried to find out why - but all things ( buttons, pdfViewer in .xaml , ModelView etc. ) are the same as in your project. whole Xaml for main window in my project was copied from your project.

BUT! It works, when I set DocumentSourse property in constructor in my ModelView - it normally shows me document, but buttons dont work. I even tried different approaches for button's command : RelayCommand and your DelegateCommand, but result was the same. Also I tried locat files the same way like you - like embedded resource, and locate files somewhere else on disk C - result was the same. 

So, can you look at my simple project and tell me, why my project doesn't work? Of course, I can use your project for my application, but I would like to understand pdfViewer to be able to work with not, not just edit your sample solution.

Thank you in advance!

Best regards,
Alexander Panteleev

0
Georgi
Telerik team
answered on 23 May 2019, 11:50 AM
Hi Alexander,

After looking at the project you have provided, I noticed that the ViewModelBase class doesn't implement the INotifyPropertyChanged interface. In WPF the source must implement this interface in order the target to track for the property changes.

I hope this helps.

Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Georgi
Telerik team
answered on 23 May 2019, 01:02 PM
Hello Alexander,

Since the sample project you have provided contains Telerik dll files I have modified your last answer to remove the link to the project. The redistribution of Telerik Programs to non-authorized end-users is prohibited and violates with our End-User License Agreement. My advice is to take advantage of our private support system included in your license when you need to send attachments. You can send us support tickets through your account in Telerik.com.

Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alexander
Top achievements
Rank 1
answered on 07 Jun 2019, 08:20 AM
[***SLAP***] [***SLAP***] - They were sounds of two my facepalms.

Hello, Georgi, thank you so much for your help. I thought that if I implement PropertyChanged event - there is no need to implement interface INotifyPropertyChanged interface...It was the first facepalm.

And the second - thank you for deleting my message with link with the project. Just no comments. Next time I will use support ticket, as you advised.

Hope, You will never get questions and messages in forums like this.

Best regards,
Alexander
0
Georgi
Telerik team
answered on 11 Jun 2019, 01:20 PM
Hi Alexander,

Don't worry, we are happy to hear you have achieved the desired result.

Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PDFViewer
Asked by
Alexander
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Alexander
Top achievements
Rank 1
Share this question
or