Search code examples
c#wpftextblock

Delayed double click for editing textblock WPF


I am trying to make it so a certain textblock turns editable with a delayed double click. Similar to the functionality in Windows Explorer when you do a delayed double click to edit file and folder names. Is this possible?


Solution

  • What you are seeing in Windows Explorer is a single-click on a selected/focused item initiating a rename operation. The first click you're seeing actually selects/focuses the item and the second click initiates the rename operation. You can verify this by using the keyboard to select a different item and then single-clicking on the newly selected item.

    It appears that there is a short duration (e.g. half a second) between the click on a selected/focused item and the UI going into rename mode. So... if an item is clicked on which already has focus, you'll need to do something like starting a timer. If that item still has focus when the timer expires, enter your renaming mode.

    From there it is just a matter of applying the correct template with whichever trigger/flag logic you care to implement.

    EDIT: Do a search on WPF in-place editing and you should find some code examples.

    NOTE: The F2 key also tends to initiate rename operations on selected items if you want to wire that in as well.