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; //} } }
public override void OnApplyTemplate() { base.OnApplyTemplate(); //this.PART_TextBox = this.GetTemplateChild("PART_TextBox") as TextBlock; this.PART_DateSelector = this.GetTemplateChild("PART_DateSelector") as DateSelector; this.PART_Popup = this.GetTemplateChild("PART_Popup") as Popup; if (DateMode == DateMode.None) { PART_PreviousButton = this.GetTemplateChild("PART_NextButton") as Button; PART_NextButton = this.GetTemplateChild("PART_PreviousButton") as Button; PART_TextBox = this.GetTemplateChild("PART_TextBox") as NumbericTextBox; PART_TextBox.TextChanged += PART_TextBox_TextChanged; } else { PART_PreviousButton = this.GetTemplateChild("PART_PreviousButton") as Button; PART_NextButton = this.GetTemplateChild("PART_NextButton") as Button; } if (this.PART_DateSelector != null) { this.PART_DateSelector.Owner = this; this.PART_DateSelector.SelectedTimeChanged += PART_DateSelector_SelectedTimeChanged; if (PART_PreviousButton != null) { this.PART_PreviousButton.AddHandler(MouseLeftButtonDownEvent, new RoutedEventHandler(PART_PreviousButton_Click), true); } if (PART_NextButton != null) { this.PART_NextButton.AddHandler(MouseLeftButtonDownEvent, new RoutedEventHandler(PART_NextButton_Click), true); } } if (this.PART_Popup != null) { this.PART_Popup.Opened += PART_Popup_Opened; } if (SelectedTime == null) { SelectedTime = Global.SystemTime; } }