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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer "Spring seems like it could be a nice fit, but… May 11, 2026 at 6:03 pm
  • Editorial Team
    Editorial Team added an answer Q1: yes. you can throw any type, not necessary types… May 11, 2026 at 6:03 pm
  • Editorial Team
    Editorial Team added an answer This seems to be a bug in the documentation. The… May 11, 2026 at 6:03 pm

Related Questions

I having trouble with a simple question : How to have some disabled field
I would normally use Google analytics because it is free and simple to implement
I am trying to modify the default style of the ContextMenu in WPF. Normally
This seems so tricky to me that I think I am overlooking something simple

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.