e.失去焦点时处理日期选择器 [英] e.Handle in Date picker while lostfocus

查看:126
本文介绍了e.失去焦点时处理日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

e.handle在日期选择器LostFocus中不起作用,代码如下
请帮助,谢谢

如果已经失去焦点,则会引发

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;
    }

}

推荐答案

LostFocus.您的支票应放在 Validating [ ^ ]事件海事组织.

抱歉,我只是没有注意到WPF标签.
可能是,本文可以为您提供帮助. Windows Presentation Foundation中的验证 [ http://stackoverflow.com/questions/2610883/date-picker-validation-wpf [ ^ ]
LostFocus is raised when focus is already lost. Your check should be placed in Validating[^] event IMO.

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[^]


这篇关于e.失去焦点时处理日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆