How can I clear my TextBox when it is focused? I want to do this in MVVM way. If it has meaning – my TextBox control has Text property binded with some property in ViewModel. TextBox displays sth like “50,30 zł”. It is uncomfortable for user to select text, delete it and write new text, so I want to clear old Text when Texbox is focused.
Share
You can write your own behavior or even control.
I will try to explain the first one:
First, you should a add reference to the System.Windows.Interactivity assembly.
Then create a class (which will be the behavior) and derive it from System.Windows.Interactivity.Behavior< System.Windows.Controls.TextBox>, where templated (generic type) parameter is a control which should behave as I described.
For example:
Next, put the following reference declaration in your parent window in xaml
Finally add the behavior to the appropriate UI element(TextBox in our case):