'How to set CarretIndex for TextBox

I defined a TextBox, listening on PropertyChanged...

<TextBox x:Name="FreeSearchTBX" Text="{Binding FreeSearchText, UpdateSourceTrigger=PropertyChanged}"/>

FreeSearchText is a string executing an async Task when its set method is called. While the execution of the task might take a little while, the TextBox has some strange behaviour when I set its IsAsync property to true. Whenever I type something in my TextBox, the cursor will jump straight to the first position of the text.

Hence, I was thinking to set the CarretIndex, but here I cannot use bindings. I was thinking to use simply the length of FreeSearchText but that seems not possible.

How can I get rid of this strange behavior of the TextBox when IsAsync = true?

I am following MVVM and would like to stay as much as possible out of the code-behind file.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source