Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF TextBox - programatically select text while preserving "selection direction"

When editing text the user is able to use the keybord shift button and direction keys to modify the selection - one position stays anchored while the other moves. By pressing left it is possible to get the movable part on the left of the anchored part.

I'm trying to dinamicaly modify the users selection in WPF's TextBox (for the purpose of the discussion, lets say I want to select the characters in pairs, eg. when pressing shift+left, 2 characters would get selected, not just one). However, when using SelectionStart/SelectionIndex/CaretIndex/Select the "movebale end" of the selection is always ends up on the far right end of the selection, rendering the shift+left combination useless.

Any way to preserve the "selection direction"?

like image 904
Hrvoje Prgeša Avatar asked Oct 17 '09 11:10

Hrvoje Prgeša


1 Answers

This is not quite the answer you are looking for but it'll work. Invoke the command and do it the way WPF does it.

     EditingCommands.SelectLeftByCharacter.Execute(null, textBox1);
like image 172
Robert Jeppesen Avatar answered Nov 09 '22 05:11

Robert Jeppesen