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 7801231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:52:56+00:00 2026-06-02T00:52:56+00:00

I want to disable the selection of text in a textbox using a style

  • 0

I want to disable the selection of text in a textbox using a style preferably. The reason is that I have a style that makes a textbox look like a textblock until a certain criteria (IsRenaming) is met. These are the nodes of a treeview so I don’t want the user to be able to select the text. Here is the style:

<Style x:Key="TextBlockStyleForTextBox" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="IsReadOnly" Value="True" />
</Style>

<Style x:Key="RenamingTextBox" TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBlockStyleForTextBox}">
        <Setter Property="Cursor" Value="Arrow"/>
        <Setter Property="Padding" Value="0" />
        <Setter Property="Margin" Value="0" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsRenaming}" Value="true">
                <DataTrigger.Setters>
                    <Setter Property="TextBox.IsReadOnly" Value="False" />
                    <Setter Property="Cursor" Value="IBeam" />
                    <Setter Property="Background" >
                        <Setter.Value>
                            <SolidColorBrush Color="{DynamicResource WhiteColor}"/>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="BorderThickness" Value="1" />
                    <Setter Property="Padding" Value="2" />
                    <Setter Property="FocusManager.FocusedElement" Value="{Binding RelativeSource={RelativeSource Self}}"/>
                    <Setter Property="behaviors:TextBoxBehavior.SelectAll" Value="True"/>
                </DataTrigger.Setters>
            </DataTrigger>
        </Style.Triggers>
    </Style>

I don’t think I am overriding the IsReadOnly anywhere. Here is my textbox definition:

<DataTemplate x:Key="MyTemplate" >
        <TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" 
                 Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=TreeView}}"
                 Style="{StaticResource RenamingTextBox}">

… etc

  • 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. Editorial Team
    Editorial Team
    2026-06-02T00:52:58+00:00Added an answer on June 2, 2026 at 12:52 am

    This is quick and dirty, but it’s a good start/example from our conversation in the other answer, you can and additional tweaks to the style, but it totally works (just tested it)

    <Style x:Key="RenamingTextBox" TargetType="{x:Type TextBox}">
            <Style.Setters>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TextBox}">
                            <Grid>
                                <TextBlock x:Name="block" Visibility="Visible" Text="{TemplateBinding Text}" Margin="1.5"/>
                                <TextBox x:Name="box" Visibility="Collapsed" Text="{TemplateBinding Text}"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <DataTrigger Binding="{Binding IsRenaming}" Value="true">
                                    <DataTrigger.Setters>
                                        <Setter TargetName="block" Property="TextBox.Visibility" Value="Collapsed" />
                                        <Setter TargetName="box" Property="TextBox.Visibility" Value="Visible" />
                                    </DataTrigger.Setters>
                                </DataTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style.Setters>
        </Style>    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to enable/disable a text box based on selection of drop down items
I want to disable a set of checkbox based on selection of one textbox
I want to disable text selection for specific elements. For example: p { -moz-user-select:
I would like to have an ordered list that has the text on the
Possible Duplicate: css rule to disable text selection highlighting On my homepage i have
I want to disable click on a certain <div> so that when you select
I've 3 text fields and I have 3 checkboxes attached with it. I want
I have a program that displays information(simple text, but not in a txt box,
Is there a way using JavaScript to disable the ability to paste text into
I have a list of divs that I want to be able to sort.

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.