private void dp_endedatum_GotKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e) { DatePickerTextBox dptb_endedatum = (DatePickerTextBox)dp_endedatum.Template.FindName("PART_TextBox", dp_endedatum); if (dptb_endedatum != null) { dptb_endedatum.SelectAll(); } }
private void Dp_geburtsdatum_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { DatePickerTextBox dptb_geburtsdatum = (DatePickerTextBox)dp_geburtsdatum.Template.FindName("PART_TextBox", dp_geburtsdatum); if (dptb_geburtsdatum != null) { dptb_geburtsdatum.SelectAll(); } }
/// <summary> /// 验证数据有效性,无效撤销 /// </summary> /// <returns></returns> private bool IsOk() { //验证日期的正确性 if (!Regex.IsMatch(_datePickerTextBox.Text.Trim(), @"^(((((1[6-9]|[2-9]\d)\d{2})/(0?[13578]|1[02])/(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})/(0?[13456789]|1[012])/(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})/0?2/(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))/0?2/29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d)$")) { _datePickerTextBox.SelectAll(); _datePickerTextBox.SelectedText = ""; return(false); } return(true); }