---
title: "TextBox readonly “on/off” between “double click and lost focus events” in wpf"  
description: "TextBox readonly “on/off” between “double click and lost focus events” in wpf"  
author: "Jayden Bell"  
published: 2013-09-24  
updated: 2013-09-24  
canonical: https://www.mindstick.com/forum/1516/textbox-readonly-on-off-between-double-click-and-lost-focus-events-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# TextBox readonly “on/off” between “double click and lost focus events” in wpf

I have a [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control) like below xaml with Read only enabled.

<[TextBox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) Text="{[Binding](https://www.mindstick.com/blog/146/dynamic-binding-in-c-sharp) Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" [Background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp)="[Transparent](https://www.mindstick.com/forum/1784/wpf-webbrowser-on-transparent-window)" IsReadOnly="True" BorderThickness="0" TextWrapping="Wrap" >

Now when i [double click](https://www.mindstick.com/forum/155692/what-is-dfp-double-click-for-publisher) this text box , i should be able to enter texts. that is my [readonly](https://www.mindstick.com/forum/1419/how-can-i-make-the-wpf-datagrid-cells-readonly) should become false

If i move to another item in the window other than this text box , then i my text box should become readonly again.

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) in WPF Trigget. but not getting the right hint . Can [anyone help me](https://www.mindstick.com/forum/331/can-anyone-help-me-out-how-to-use-session-concept) here ?

## Replies

### Reply by Pravesh Singh

Hi Jayden,

You can make this with 2 events, MouseDoubleClick and LostFocus

```
<Grid>    <TextBox
IsReadOnly="True"            
MouseDoubleClick="TextBox_MouseDoubleClick"            
LostFocus="TextBox_LostFocus"/></Grid>
```

## In you procedural code:

```
private void TextBox_MouseDoubleClick(object sender,MouseButtonEventArgs e){    TextBox textBox =sender as TextBox;    textBox.IsReadOnly= false;   
//textBox.CaretIndex = textBox.Text.Count();    textBox.SelectAll();}private void TextBox_LostFocus(object sender,RoutedEventArgs e){    TextBox textBox =sender as TextBox;    textBox.IsReadOnly= true;}
```


---

Original Source: https://www.mindstick.com/forum/1516/textbox-readonly-on-off-between-double-click-and-lost-focus-events-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
