Click here to Skip to main content
15,910,787 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear all,

e.handle not working in Date picker LostFocus the code follows
help please and thanks

private void datePicker1_LostFocus(object sender, RoutedEventArgs e)
  {

    DateTime StartDate = new DateTime(2011, 4, 1);
    DateTime EndDate = new DateTime(2011, 4, 1);

    DatePicker dDate = (DatePicker)sender;
    //DateTime ddate = dDate.DisplayDate;

    if ((dDate.DisplayDate >= StartDate) && dDate == null)      // && (StartDate <= dDate.DisplayDate))
    {
        MessageBox.Show("good");
    }
    else
    {
        MessageBox.Show("bad");

        e.Handled = true;
    }

}
Posted

1 solution

LostFocus is raised when focus is already lost. Your check should be placed in Validating[^] event IMO.
[Edit]
Sorry, I just didn't notice the WPF tag.
May be, this article can help you. Validation in Windows Presentation Foundation[^]
Check the validation rule,
http://stackoverflow.com/questions/2610883/date-picker-validation-wpf[^]
 
Share this answer
 
v3
Comments
gpasupathi 6-Sep-11 4:56am    
Dear Sir, thanks and sorry for the delayed replay. I could not understand of the articale of Validation in WPF. any simple date validation in WPF
Prerak Patel 6-Sep-11 5:20am    
Check this
http://stackoverflow.com/questions/2610883/date-picker-validation-wpf

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