private void PART_TextBox_TextChanged(object sender, TextChangedEventArgs e) { NumbericTextBox textBox = e.OriginalSource as NumbericTextBox; SelectorPicker selectorPicker = GetParentObject <SelectorPicker>(textBox, ""); if (selectorPicker != null) { //System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(@"^[1-9]\d{0,2}$"); textBox.Text = textBox.Text.Length > 1 ? textBox.Text.TrimStart('0'): textBox.Text; if (!string.IsNullOrWhiteSpace(textBox.Text)) { int newValue = int.Parse(textBox.Text.Trim()); if (newValue > textBox.MaxValue) { selectorPicker.Value = int.Parse(textBox.MaxValue.ToString()); } else if (newValue < textBox.MinValue) { selectorPicker.Value = int.Parse(textBox.MinValue.ToString()); } else { selectorPicker.Value = newValue; } } selectorPicker.OnNumbericTextBoxChanged(null, null); //else //{ // selectorPicker.Value = selectorPicker.MinValue; //} } }
private static void ValueChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { SelectorPicker timePicker = d as SelectorPicker; if (timePicker.DateMode == DateMode.None) { timePicker.SelectedTimeString = e.NewValue.ToString(); } }
private static void SelectedTimeChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue != null) { SelectorPicker timePicker = d as SelectorPicker; DateTime dt = (DateTime)e.NewValue; if (timePicker.DateMode != DateMode.None) { timePicker.SelectedTimeString = dt.ToString(timePicker.StringFormat); } if (timePicker.PART_DateSelector != null) { timePicker.PART_DateSelector.SelectedTime = dt; } timePicker.OnSelectedTimeChanged((DateTime?)e.OldValue, (DateTime?)e.NewValue); } }
private static object OnValueCoerceValueCallback(DependencyObject d, object baseValue) { //不让超出边界暂时没有相关计算 SelectorPicker timePicker = d as SelectorPicker; int value = Convert.ToInt32(baseValue); if (value > timePicker.MaxValue) { return(timePicker.MaxValue); } else if (value < timePicker.MinValue) { return(timePicker.MinValue); } else { return(baseValue); } }
private static void DateModeChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { SelectorPicker timePicker = d as SelectorPicker; DateMode dateMode = (DateMode)e.NewValue; if (dateMode == DateMode.Day) { timePicker.StringFormat = "dd日"; } else if (dateMode == DateMode.Month) { timePicker.StringFormat = "MM月"; } else if (dateMode == DateMode.Year) { timePicker.StringFormat = "yyyy年"; } else if (dateMode == DateMode.YearMonth) { timePicker.StringFormat = "yyyy年MM月"; } else if (dateMode == DateMode.YearMonthDay) { timePicker.StringFormat = "yyyy年MM月dd日"; } else if (dateMode == DateMode.MonthDay) { timePicker.StringFormat = "MM月dd日"; } if (dateMode == DateMode.None) { timePicker.SelectedTimeString = timePicker.Value.ToString(); } else if (timePicker.SelectedTime != null) { timePicker.SelectedTimeString = timePicker.SelectedTime.Value.ToString(timePicker.StringFormat); } }