How do I add a ContextMenu for the PDFViewer?
I've tried this;
<telerik:RadContextMenu.ContextMenu>
<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}"/>
</telerik:RadContextMenu>
But the menu items don't do anything.
Thanks.
I've tried this;
<telerik:RadContextMenu.ContextMenu>
<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}"/>
</telerik:RadContextMenu>
But the menu items don't do anything.
Thanks.
4 Answers, 1 is accepted
0
Seth
Top achievements
Rank 1
answered on 20 Jun 2013, 08:35 PM
I see the winForms version of pdfViewer has the contextMenu by default.
What am I missing to make this work with WPF?
What am I missing to make this work with WPF?
0
Accepted
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.
Regards,
Alexander
Telerik
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.
Regards,
Alexander
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
0
armando
Top achievements
Rank 1
answered on 30 Jan 2015, 10:48 PM
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}}"
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}}"
0
Hello Armando,
Thank you for the interest in RadPdfViewer.
Here is an attached property that will set the proper DataContext to the context menu.
You can use it from Xaml like this:
Hope this helps.
Regards,
Kammen
Telerik
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 ...>
<l:PdfViewerContextMenuHelper.ContextMenu>
<telerik:RadContextMenu
>
...
</telerik:RadContextMenu>
</l:PdfViewerContextMenuHelper.ContextMenu>
</telerik:RadPdfViewer>
Hope this helps.
Regards,
Kammen
Telerik
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.