5 posts, 1 answers
  1. Seth
    Seth avatar
    5 posts
    Member since:
    Oct 2012

    Posted 19 Jun 2013 Link to this post

    How do I add a ContextMenu for the PDFViewer?

    I've tried this;
                        <telerik:RadContextMenu DataContext="{Binding ElementName=pdfViewer, Path=Commands}">
                            <telerik:RadMenuItem Header="Copy" Command="{Binding CopyCommand}"/>
                            <telerik:RadMenuItem Header="Select All" Command="{Binding SelectAllCommand}"/>
                            <telerik:RadMenuItem Header="Print..." Command="{Binding PrintPdfDocumentCommand}"/>

    But the menu items don't do anything.

  2. Seth
    Seth avatar
    5 posts
    Member since:
    Oct 2012

    Posted 20 Jun 2013 Link to this post

    I see the winForms version of pdfViewer has the contextMenu by default.

    What am I missing to make this work with WPF?
  3. Answer
    Alexander avatar
    41 posts

    Posted 21 Jun 2013 Link to this post

    Hi Seth,

    The DataContext must be set inside the RadPdfViewer or another parent element in order to be inherited by the RadContextMenu correctly, because RadContextMenu is represented in a different visual tree.
    I am attaching a sample project which demonstrates how to create RadContextMenu inside RadPdfViewer.

    I hope this is helpful. Please, do not hesitate to contact us if you have any other questions.


    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  4. armando
    armando avatar
    2 posts
    Member since:
    Jan 2015

    Posted 30 Jan 2015 in reply to Alexander Link to this post

    Hi alexander, 
    your solution does not work when the pdf viewer is binded to a viewmodel.
    In my case DocumentSource is binded to a viewmodel property and if I set the datacontext as per your example I am not able to show the document any more

     <telerik:RadPdfViewer x:Name="pdfViewer"  DocumentSource="{Binding PdfSource,                                                                     Converter={StaticResource PdfDocumentSourceValueConverter}}"
                                                          Style="{DynamicResource RadPdfViewerStyle}"
                                                          Visibility="{Binding Path=IsVisible,
                                                                               Converter={StaticResource BoolToVisibilityConverter}}"

  5. Kammen
    Kammen avatar
    382 posts

    Posted 04 Feb 2015 Link to this post

    Hello Armando,

    Thank you for the interest in RadPdfViewer.

    Here is an attached property that will set the proper DataContext to the context menu.

    public static class PdfViewerContextMenuHelper
        public static readonly DependencyProperty ContextMenuProperty =
            DependencyProperty.RegisterAttached("ContextMenu", typeof(RadContextMenu), typeof(PdfViewerContextMenuHelper), new PropertyMetadata(null, new PropertyChangedCallback((s, e) => { ContextMenuChanged((RadPdfViewer)s, (RadContextMenu)e.NewValue); })));
        public static RadContextMenu GetContextMenu(DependencyObject obj)
            return (RadContextMenu)obj.GetValue(ContextMenuProperty);
        public static void SetContextMenu(DependencyObject obj, RadContextMenu value)
            obj.SetValue(ContextMenuProperty, value);
        private static void ContextMenuChanged(RadPdfViewer radPdfViewer, RadContextMenu contextMenu)
            contextMenu.InheritDataContext = false;
            RadContextMenu.SetContextMenu(radPdfViewer, contextMenu);
            contextMenu.DataContext = radPdfViewer.CommandDescriptors;

    You can use it from Xaml like this:
    <telerik:RadPdfViewer  ...>

    Hope this helps.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top