#932 – Making a TextBox Read-Only or Disabled

You can control a couple of different things with the IsEnabled and IsReadOnly properties of a TextBox.

  • IsEnabled – When false, user can’t interact with the control in any way and the control is greyed out.  (Default is true)
  • IsReadOnly – When true, user can’t edit or enter text, but can still scroll, select text and copy.

Typical combinations:

  • IsEnabledtrue, IsReadOnly = false — standard behavior, editable text
  • IsEnabled = true, IsReadOnly = true — read-only text, user can scroll/copy
  • IsEnabled = false — user can’t interact with TextBox at all
            <RowDefinition Height="Auto"/>

        <TextBox Name="txtMain" Margin="5"
                 Text="{Binding SomeText}"
                 IsReadOnly="{Binding ElementName=chkReadOnly, Path=IsChecked}"
                 IsEnabled="{Binding ElementName=chkEnabled, Path=IsChecked}"/>
        <StackPanel Orientation="Horizontal" Grid.Row="1">
            <CheckBox Name="chkReadOnly" Content="IsReadOnly" />
            <CheckBox Name="chkEnabled" Content="IsEnabled" />


About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

2 Responses to #932 – Making a TextBox Read-Only or Disabled

  1. Pingback: Dew Drop – October 21, 2013 (#1,649) | Morning Dew

  2. SK says:

    You are doing excellent job but please include the solution/project files similar to CodeProject site. This will help people to download and run at their end. Again, appreciate for your hard work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: