NextInLine
NextInLine

Reputation: 2204

How do I disable the context menu of FlowDocumentScrollViewer, FlowDocumentPageViewer, or FlowDocumentReader?

When displaying FlowDocument in WPF, how do I disable the right-click context menu of the FlowDocumentScrollViewer, FlowDocumentPageViewer, or FlowDocumentReader?

I'd like a pure-XAML solution that can be used in a style, not one that requires a code-behind.

Upvotes: 2

Views: 273

Answers (1)

Avestura
Avestura

Reputation: 1557

FlowDocumentScrollViewer and FlowDocumentPageViewer:

You can use ContextMenuService.IsEnabled property.

<FlowDocumentPageViewer ContextMenuService.IsEnabled="False" />

Or set context menu to null using {x:Null} markup extension.

<FlowDocumentPageViewer ContextMenu="{x:Null}" />

I personally prefer first one because is more readable.


FlowDocumentReader:

Above methods doesn't work for FlowDocumentReader, try using this:

<FlowDocumentReader>
   <FlowDocument>
       <FlowDocument.ContextMenu>
           <ContextMenu Visibility="Collapsed" />
       </FlowDocument.ContextMenu>
   </FlowDocument>
</FlowDocumentReader>

Upvotes: 1

Related Questions