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

Custom command in context menu of PDF viewer (MVVM)

1 Answer 263 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 10 Jul 2019, 09:20 AM

Hello,
I would like to ask about context menu of PDF viewer.

So, I have PDF viewer (which is located in some UserControl), it works fine. In my app I allow to user creating of custom bookmarks - just some name and page number. One of the ways, how can user create own bookmark - right click and choose create bookmark in context menu. To create this I would like to use custom RelayCommand, which is in ViewModel of MainWindow and also uses some properties from ViewModel of MainWindow.

So, there is some problem. Since PdfViewer has it own DataContext (Command Descriptors), I can't use PlacementTarget to get some information from Window/UserControl DataContext (I tried relative source - it doesn't work). I found a solution - I created addition class with own RelayCommand, that works with STATIC variables (instance of PDF viewer to get current page) and methods (to create bookmark) from ViewModel. But I really dont like it really this solution.

So, I would like to ask you, how can I use my custom command from ViewModel in context menu of Pdf viewer? Or at least how can I pass CurrentPageNumer as argument, when I click on my custom menu item (command from custom class, which is initialized as static resource) in contextmenu of PDFviewer?

Now it looks like that:
<telerik:RadMenuItem Header="Create Custom Bookmark" Command="{Binding SomeCommand, Source={StaticResource customClass}}"    
                                                 Visibility="Visible" >

Thank you in advance!
Best regards,
Alexander

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 12 Jul 2019, 02:40 PM
Hi Alexander,

If I am understanding your scenario correctly, you would like to bind a custom command to a custom menu item of the context menu. If so, you can achieve the desired result by creating a custom command descriptors and apply them to the CommandDescriptors property of RadPdfViewer. You can create custom command by inheriting from the FixedDocumentViewerCommandBase class and add it to the CommandDescriptors by extending the DefaultCommandDescriptors class as can be seen in the Command Descriptors section of the documentation. The FixedDocumentViewerCommandBase class keeps a reference to a FixedDocumentViewerBase instance, which is the base class for RadPdfViewer. This way when the command is executed you will have access to the CurrentPageNumber property.

I hope this is helpful.

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
Share this question
or