Click here to Skip to main content
15,899,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have built a WPF-UserControl that is to accept a date value. For the control is equipped with 3 TextBoxes. For day, month and year.
When the user enters a number for the day, the entered value is checked for logical validity about the event "TextBox_PreviewLostKeyboardFocus". (Only not > 31).
If the value is valid, then the focus is automatically shifted to the TextBox for the month. Is the value not valid, then forwarding the focus will be canceled and selects the specified value. The same procedure for the month (only not > 12). After entering the value for Year, the Inputs are checked for Leapyear (February 29, 2000 = o.k, 2001 = wrong). The user must Change the input.

If the control is left by the user, then about the event "Control_PreviewLostKeyboardFocus" the inputs are checked for a valid date. Are all TextBoxes empty, this ist o.k. too. This case must be checked by the application which uses my UserControl.

And now the Problem:
The event "Control_PreviewLostKeyboardFocus" is raised first by any TextBoxFocus change.

Is it possible to manipulate the raising of "Control_PreviewLostKeyboardFocus"? Or is there an other way to check the Input?

Thanks in advance.
Posted
Updated 8-Apr-15 21:58pm
v2
Comments
Herman<T>.Instance 9-Apr-15 4:06am    
What's the tabindexes of these controls?
oldboy24 9-Apr-15 6:33am    
Hi, digimanus! What do you mean about "tabindexes"?
Herman<T>.Instance 9-Apr-15 6:50am    
Hi oldboy24,
controls hav a TabIndex. It is their nr in the Tab Order. When you press TAB you go to the next control...
oldboy24 9-Apr-15 12:38pm    
The TabIndex of my 3 TextBoxes in my UserControl - I have now changed to 1, 2 and 3.(They had have the Default). The behavior did not change.
If the user enter the caret (with the mouse) in one TextBox (for day, month or year) it raises the "UserControl_PreviewLostKeyboardFocus" - event first. This event should check the Inputs of the TextBoxes. All empty or a valid date - is o.k. But if one TextBox or 2 TextBoxes are empty, this is wrong. In this case I Show a MessageBox and put the Focus to one of the empty TextBoxes.
Herman<T>.Instance 9-Apr-15 13:34pm    
The event is raised because you enter a TextBox object whoch is not the UserControl object. Do you really need this event?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900