/// <summary> /// Called when property changes. /// </summary> /// <param name="d">The dependency object.</param> /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.OldValue != e.NewValue) { DateLabel dateLabel = d as DateLabel; if (dateLabel != null) { if (dateLabel.Value != null) { if (e.Property == DateTypeProperty) { if (Enum.IsDefined(typeof(DateType), e.NewValue)) { dateLabel.Value.DateType = (DateType)e.NewValue; } else { dateLabel.Value.DateType = DateType.Exact; } } else if (e.Property == DateValueProperty) { dateLabel.Value.DateValue = (DateTime)e.NewValue; } else if (e.Property == MonthProperty) { dateLabel.Value.Month = (int)e.NewValue; } else if (e.Property == NullIndexProperty) { dateLabel.Value.NullIndex = (int)e.NewValue; } else if (e.Property == YearProperty) { dateLabel.Value.Year = (int)e.NewValue; } else if (e.Property == ValueProperty) { CuiDate cd = e.NewValue as CuiDate; if (cd != null) { dateLabel.DateType = cd.DateType; dateLabel.DateValue = cd.DateValue; dateLabel.Month = cd.Month; dateLabel.NullIndex = cd.NullIndex; dateLabel.Year = cd.Year; } } } dateLabel.UpdateDisplayValue(); AutomationPeerValueChanged(e, dateLabel); } } }
/// <summary> /// Convert back function. /// </summary> /// <param name="value">The source value.</param> /// <param name="targetType">The target type.</param> /// <param name="parameter">The parameter.</param> /// <param name="culture">The culture info.</param> /// <returns>The converted back value.</returns> public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return(null); } CuiDate cuiDate = new CuiDate(value.ToString()); if (!cuiDate.IsNull) { return(cuiDate.DateValue); } return(null); }
/// <summary> /// Updates the date in the text box, if necessary. /// </summary> /// <param name="sender">The date input box.</param> /// <param name="e">Selection Changed Event Args.</param> private void DateInputBox_SelectedDateChanged(object sender, SelectionChangedEventArgs e) { if (this.textBox != null) { CuiDate cuiDate = new CuiDate(this.textBox.Text); if (string.IsNullOrEmpty(this.textBox.Text) || cuiDate.DateValue != this.SelectedDate) { this.textBox.Text = this.SelectedDateText; } } if (this.ShowSelectedDateChangedState) { VisualStateManager.GoToState(this, "SelectedDateCleared", false); VisualStateManager.GoToState(this, "SelectedDateChanged", true); } }
/// <summary> /// Updates the selected date with the text box text. /// </summary> private void UpdateSelectedDate() { if (this.textBox != null) { CuiDate cuiDate = null; if (CuiDate.TryParseExact(this.textBox.Text, out cuiDate, CultureInfo.CurrentCulture)) { } else if (CuiDate.IsAddValid(this.textBox.Text)) { cuiDate = CuiDate.Add(new CuiDate(DateTime.Now), this.textBox.Text); } if (cuiDate != null && !cuiDate.IsNull && cuiDate.ToString().Length >= 11 && (!this.SelectedDate.HasValue || cuiDate.DateValue != this.SelectedDate.Value.Date)) { this.SelectedDate = cuiDate.DateValue; } this.textBox.Text = this.SelectedDateText; } }
/// <summary> /// Convert back function. /// </summary> /// <param name="value">The source value.</param> /// <param name="targetType">The target type.</param> /// <param name="parameter">The parameter.</param> /// <param name="culture">The culture info.</param> /// <returns>The converted back value.</returns> public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return null; } CuiDate cuiDate = new CuiDate(value.ToString()); if (!cuiDate.IsNull) { return cuiDate.DateValue; } return null; }