Only once? I have a whole CodeProject article on this problem:
Wish You Were Here… Only Once[
^].
Note that you don't have to use my highly universal approach, which is created mostly to demonstrate the possibility of context-sensitive condition techniques and also for curiosity, even though my technique is not only highly universal but also quite usable practically. It's more important for deeper understanding of some fundamentals of programming. But you can use the elementary technique I overview in the very beginning. Understanding is what you actually need the most.
[EDIT]
Yes, you are right, your problem is quite different, and the problem is: you don't properly understand the concept of data input and related events.
Here is the thing: when a user enters (or even deletes) a single character, this is the event, but when the user decides that all characters are properly edited, it is not an event, because this is all in the user's head, nowhere.
It means that your whole concept is wrong. You need to require the user to actually confirm that the output is done. For example, press Enter (which you can detect handling
KeyDown
or
KeyUp
event, moves the keyboard focus (which you can detect handling
LostFocus
event):
http://msdn.microsoft.com/en-us/library/system.windows.uielement.keydown(v=vs.110).aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.uielement.keyup(v=vs.110).aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.uielement.lostfocus(v=vs.110).aspx[
^].
Alternatively, you could detect that all positions are filled if you use something like the
MaskedTextBox
control, such as this one:
http://wpftoolkit.codeplex.com/wikipage?title=MaskedTextBox[
^].
However, I don't think that these two approaches, which are certainly working, are the best. I think the best option would be not handling this events for such an uncertain purpose at all. Instead, I would recommend to validate all input at the very point where the input data can are about to be used. Then you can sanitize data, and, if data is unsatisfiable, focus the "offending" input control and provide the user with explanation what requirements are not met.
This approach, despite its simplicity, is more flexible. I'll explain why: what if validity of data entered in one control depends on the states of some other controls? Such complication is pretty usual. So, validation and sanitation all of the entered data at once is more universal approach.
—SA