Is there an easy way to have a text box display a format in a text box and remove it when editing ?
Example : I want to ask for a money value. When the user finished entering the value 5.5, it displays $ 5.00 . When the user reclick on the textbox, it should switch back to 5.5 .
Thanks you.
Edit : What I am trying to do would be the equivalent of a converter except the textbox does not have a binding set to it.
There’s a couple of solutions for this. Perhaps the easiest would be to implement a custom Behavior (you’ll need to reference System.Windows.Interactivity.dll) & hook onto some events TextBox exposes, like GotFocus and LostFocus. Here’s a sample I’ve done for selecting all of a TextBox’s text when it gets focused:
Edit: Forgot to show how to hook the behavior up to the TextBox.
To attach the Behavior, in your XAML you’ll need to add a namespace reference to your Behavior’s namespace, and then attach it as a child of the TextBox markup like so:
You could do something similar, though with yours you’d want to hook up to the LostFocus-related events and adjust the contents of the TextBox’s Text property.