private static void OnLabelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { MaterialComboBox box = d as MaterialComboBox; if (box != null && box.inputLabel != null) { box.inputLabel.Text = box.Label; } }
private void BoxYear_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (sender is MaterialComboBox) { MaterialComboBox box = (MaterialComboBox)sender; if (box.SelectedItem is int) { this.Year = (int)box.SelectedItem; this.Validate(); } } }
public override void OnApplyTemplate() { base.OnApplyTemplate(); this.errorLabel = (TextBlock)GetTemplateChild("PART_ErrorLabel"); this.panel = (StackPanel)GetTemplateChild("PART_Panel"); switch (this.DateFormat) { case DateFormat.DayMonthYear: this.boxDay = (MaterialComboBox)GetTemplateChild("PART_Box1"); this.boxMonth = (MaterialComboBox)GetTemplateChild("PART_Box2"); this.boxYear = (MaterialComboBox)GetTemplateChild("PART_Box3"); break; case DateFormat.MonthDayYear: this.boxMonth = (MaterialComboBox)GetTemplateChild("PART_Box1"); this.boxDay = (MaterialComboBox)GetTemplateChild("PART_Box2"); this.boxYear = (MaterialComboBox)GetTemplateChild("PART_Box3"); break; case DateFormat.YearMonthDay: this.boxYear = (MaterialComboBox)GetTemplateChild("PART_Box1"); this.boxMonth = (MaterialComboBox)GetTemplateChild("PART_Box2"); this.boxDay = (MaterialComboBox)GetTemplateChild("PART_Box3"); break; case DateFormat.YearDayMonth: this.boxYear = (MaterialComboBox)GetTemplateChild("PART_Box1"); this.boxDay = (MaterialComboBox)GetTemplateChild("PART_Box2"); this.boxMonth = (MaterialComboBox)GetTemplateChild("PART_Box3"); break; default: break; } this.panel.Margin = this.IsFloating ? new Thickness(0, this.GetSmallFontSize() + this.GetMargin(), 0, 0) : new Thickness(0); this.boxDay.Label = this.LabelDay; this.boxMonth.Label = this.LabelMonth; this.boxYear.Label = this.LabelYear; this.boxDay.ItemsSource = this.Days(); this.boxMonth.ItemsSource = this.Months(); this.boxYear.ItemsSource = this.Years(); // Set the initial values of the boxes if (this.SelectedDate != null && !this.SelectedDate.Equals(DateTime.MinValue)) { this.boxDay.SelectedItem = this.SelectedDate.Day; this.boxMonth.SelectedItem = this.SelectedDate.Month; this.boxYear.SelectedItem = this.SelectedDate.Year; } else { if (this.Day > 0) { this.boxDay.SelectedItem = this.Day; } if (this.Month > 0) { this.boxMonth.SelectedItem = this.Month; } if (this.Year > 0) { this.boxYear.SelectedItem = this.Year; } } this.boxDay.SelectionChanged += BoxDay_SelectionChanged; this.boxMonth.SelectionChanged += BoxMonth_SelectionChanged; this.boxYear.SelectionChanged += BoxYear_SelectionChanged; this.SetErrorLabel(); }