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

你可能感兴趣的:(WPF)