WPF DatePicker 的textbox的焦点

要得到DatePicker的textchange属性, 必须通过TextBoxBase.TextChanged 事件来处理。 

想要判断是否当前DatePicker的textbox获取到焦点, 可以通过以下代码:

  private void dtpBirth_TextChanged(object sender, TextChangedEventArgs e)
        {
            //
            IInputElement child = FocusManager.GetFocusedElement(window);

            DatePicker dtp = sender as DatePicker;

            if (null != child)
            {
                IInputElement element = dtp.InputHitTest(Mouse.GetPosition(dtp));
                if (null != element)
                {
                    dtpBirth.Tag = true;
                }               
            }
        }
posted @ 2013-07-02 11:38  muzizongheng  阅读(852)  评论(0编辑  收藏  举报
如果我们时时忙着展现自己的知识, 将何从忆起成长所需的无知?