private void YearButton_Click(object sender, RoutedEventArgs e) { DateButton selectedItem = this.PART_Year.SelectedItem as DateButton; if (selectedItem == null) { return; } this.SelectedYear = Convert.ToInt32(selectedItem.DataContext); this.PART_Year.AnimateScrollIntoView(selectedItem); }
public void SetButtonSelected() { if (!this.SelectedTime.HasValue) { return; } this.Year = this.SelectedTime.Value.Year; this.Month = this.SelectedTime.Value.Month; this.Day = this.SelectedTime.Value.Day; if (this.PART_Year != null) { for (int i = 0; i < this.PART_Year.Items.Count; i++) { DateButton timeButton = this.PART_Year.Items[i] as DateButton; if (Convert.ToString(timeButton.DataContext).Equals(Convert.ToString(this.SelectedTime.Value.Year))) { this.PART_Year.SelectedIndex = i; this.PART_Year.AnimateScrollIntoView(timeButton); break; } } } if (this.PART_Month != null) { for (int i = 0; i < this.PART_Month.Items.Count; i++) { DateButton timeButton = this.PART_Month.Items[i] as DateButton; if (Convert.ToString(timeButton.DataContext).Equals(Convert.ToString(this.SelectedTime.Value.Month))) { this.PART_Month.SelectedIndex = i; this.PART_Month.AnimateScrollIntoView(timeButton); break; } } } if (this.PART_Day != null) { for (int i = 0; i < this.PART_Day.Items.Count; i++) { DateButton timeButton = this.PART_Day.Items[i] as DateButton; if (Convert.ToString(timeButton.DataContext).Equals(Convert.ToString(this.SelectedTime.Value.Day))) { this.PART_Day.SelectedIndex = i; this.PART_Day.AnimateScrollIntoView(timeButton); break; } } } }
private void CreateItems(int itemsCount, ObservableCollection <DateButton> list, string StringFormat, int Start = 1) { for (int i = 0; i < itemsCount; i++) { int value = i + Start; DateButton timeButton = new DateButton(); timeButton.SetValue(DateButton.HeightProperty, this.ItemHeight); timeButton.SetValue(DateButton.DataContextProperty, value); timeButton.SetValue(DateButton.ContentProperty, string.Format(StringFormat, value)); timeButton.SetValue(DateButton.IsSelectedProperty, false); list.Add(timeButton); } }
private void CreateExtraItem(ObservableCollection <DateButton> list) { double height = this.ItemHeight; if (this.Owner != null) { height = this.Owner.DropDownHeight; } else { height = double.IsNaN(this.Height) ? height : this.Height; } for (int i = 0; i < (height - this.ItemHeight) / this.ItemHeight; i++) { DateButton timeButton = new DateButton(); timeButton.SetValue(DateButton.HeightProperty, this.ItemHeight); timeButton.SetValue(DateButton.IsEnabledProperty, false); timeButton.SetValue(DateButton.IsSelectedProperty, false); list.Add(timeButton); } }