Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 104747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:19:49+00:00 2026-05-11T01:19:49+00:00

Simple question. How do you disable the text selection of DocumentViewer in WPF? This

  • 0

Simple question. How do you disable the text selection of DocumentViewer in WPF? This is the feature where an XPS document is displayed by the viewer and then text can be highlighted via mouse. The highlighted text can also be copied but I have already disabled this. I just don’t know how to disable the highlighting.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:19:49+00:00Added an answer on May 11, 2026 at 1:19 am

    We have solved this by overriding the ControlTemplate of the ScrollViewer embedded in the DocumentViewer control. Insert the Style below in ‘Window.Resources’:

    <Style TargetType='{x:Type ScrollViewer}'  x:Key='CustomScrollPresenter'>     <Setter Property='Template'>         <Setter.Value>             <ControlTemplate TargetType='{x:Type ScrollViewer}'>                 <Grid Background='{TemplateBinding Panel.Background}'>                     <Grid.ColumnDefinitions>                         <ColumnDefinition Width='*' />                         <ColumnDefinition Width='Auto' />                     </Grid.ColumnDefinitions>                     <Grid.RowDefinitions>                         <RowDefinition Height='*' />                         <RowDefinition Height='Auto' />                     </Grid.RowDefinitions>                     <Rectangle Grid.Column='1' Grid.Row='1' Fill='{DynamicResource {x:Static SystemColors.ControlBrushKey}}' />                     <ScrollContentPresenter                          PreviewMouseLeftButtonDown='ScrollContentPresenter_PreviewMouseLeftButtonDown'                         Grid.Column='0'                          Grid.Row='0'                          Margin='{TemplateBinding Control.Padding}'                          Content='{TemplateBinding ContentControl.Content}'                          ContentTemplate='{TemplateBinding ContentControl.ContentTemplate}'                          CanContentScroll='{TemplateBinding ScrollViewer.CanContentScroll}' />                     <ScrollBar                          x:Name='PART_VerticalScrollBar'                         Grid.Column='1'                                 Grid.Row='0'                                 Minimum='0'                                 Maximum='{TemplateBinding ScrollViewer.ScrollableHeight}'                                 ViewportSize='{TemplateBinding ScrollViewer.ViewportHeight}'                                 Value='{Binding Path=VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}'                                 Visibility='{TemplateBinding ScrollViewer.ComputedVerticalScrollBarVisibility}'                                 Cursor='Arrow' AutomationProperties.AutomationId='VerticalScrollBar' />                     <ScrollBar                          x:Name='PART_HorizontalScrollBar'                         Orientation='Horizontal' Grid.Column='0' Grid.Row='1' Minimum='0'                                 Maximum='{TemplateBinding ScrollViewer.ScrollableWidth}' ViewportSize='{TemplateBinding ScrollViewer.ViewportWidth}' Value='{Binding Path=HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}' Visibility='{TemplateBinding ScrollViewer.ComputedHorizontalScrollBarVisibility}' Cursor='Arrow' AutomationProperties.AutomationId='HorizontalScrollBar' />                  </Grid>             </ControlTemplate>         </Setter.Value>     </Setter> </Style> 

    Then override the Style of ScrollViewer with it in the ControlTemplate for DocumentViewer:

       <Style       x:Key='MyDVStyleExtend'       BasedOn='{StaticResource {x:Type DocumentViewer}}'       TargetType='{x:Type DocumentViewer}'>        <Setter Property='Template'>                        <Setter.Value>            <ControlTemplate TargetType='DocumentViewer'>                         <Border BorderThickness='2,2,2,2'                     BorderBrush='SlateBlue' Focusable='False'>               <Grid Background='{StaticResource GridBackground}'                  KeyboardNavigation.TabNavigation='Local'>                 <Grid.ColumnDefinitions>                                     <ColumnDefinition Width ='*'/>                                                     </Grid.ColumnDefinitions>                                  <ScrollViewer Style='{StaticResource CustomScrollPresenter}'  Grid.Column ='0'                    CanContentScroll='True'                   HorizontalScrollBarVisibility='Auto'                   x:Name='PART_ContentHost'                   IsTabStop='True'/>                </Grid>             </Border>           </ControlTemplate>         </Setter.Value>       </Setter>      </Style> 

    Then create a function for the ‘PreviewMouseLeftButtonDown=’ScrollContentPresenter_PreviewMouseLeftButtonDown” attribute stated in the CustomScrollPresenter style.

      private void ScrollContentPresenter_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)     {         e.Handled = true;     } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is a simple question. How do I disable copy from a
I recently looked at the following question: How to disable text selection highlighting using
Simple question: Can a swing frame be completely modal ( block all others windows
Simple question: How do I do this on one line: my $foo = $bar->{baz};
I have a -as I hope- very simple question: how to disable an UISearchBar
This seems to be an absurdly simple question but Google and Stack Overflow searches
I can't figure out, or find any solutions to a very simple question: How
I'm sure this is a simple question. I simply cannot find it for Netbeans
i have a simple question How to disable a folder with aspx pages in
I have simple question. How to disable html tags on specific area? I tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.