private void HourButton_Click(object sender, RoutedEventArgs e)
        {
            TimeButton selectedItem = this.PART_Hour.SelectedItem as TimeButton;

            if (selectedItem == null)
            {
                return;
            }
            this.SelectedHour = Convert.ToInt32(selectedItem.DataContext);
            this.PART_Hour.AnimateScrollIntoView(selectedItem);
        }
        public void SetButtonSelected()
        {
            if (!this.SelectedTime.HasValue)
            {
                return;
            }

            this.Hour   = this.SelectedTime.Value.Hour;
            this.Minute = this.SelectedTime.Value.Minute;
            this.Second = this.SelectedTime.Value.Second;

            if (this.PART_Hour != null)
            {
                for (int i = 0; i < this.PART_Hour.Items.Count; i++)
                {
                    TimeButton timeButton = this.PART_Hour.Items[i] as TimeButton;
                    if (Convert.ToString(timeButton.Content).Equals(Convert.ToString(this.SelectedTime.Value.Hour)))
                    {
                        this.PART_Hour.SelectedIndex = i;
                        this.PART_Hour.AnimateScrollIntoView(timeButton);
                        break;
                    }
                }
            }

            if (this.PART_Minute != null)
            {
                for (int i = 0; i < this.PART_Minute.Items.Count; i++)
                {
                    TimeButton timeButton = this.PART_Minute.Items[i] as TimeButton;
                    if (Convert.ToString(timeButton.Content).Equals(Convert.ToString(this.SelectedTime.Value.Minute)))
                    {
                        this.PART_Minute.SelectedIndex = i;
                        this.PART_Minute.AnimateScrollIntoView(timeButton);
                        break;
                    }
                }
            }

            if (this.PART_Second != null)
            {
                for (int i = 0; i < this.PART_Second.Items.Count; i++)
                {
                    TimeButton timeButton = this.PART_Second.Items[i] as TimeButton;
                    if (Convert.ToString(timeButton.Content).Equals(Convert.ToString(this.SelectedTime.Value.Second)))
                    {
                        this.PART_Second.SelectedIndex = i;
                        this.PART_Second.AnimateScrollIntoView(timeButton);
                        break;
                    }
                }
            }
        }
 private void CreateItems(int itemsCount, ObservableCollection <TimeButton> list)
 {
     for (int i = 0; i < itemsCount; i++)
     {
         TimeButton timeButton = new TimeButton();
         timeButton.SetValue(TimeButton.HeightProperty, this.ItemHeight);
         timeButton.SetValue(TimeButton.DataContextProperty, i);
         timeButton.SetValue(TimeButton.ContentProperty, (i < 10) ? "0" + i : i.ToString());
         timeButton.SetValue(TimeButton.IsSelectedProperty, false);
         list.Add(timeButton);
     }
 }
        private void CreateExtraItem(ObservableCollection <TimeButton> 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++)
            {
                TimeButton timeButton = new TimeButton();
                timeButton.SetValue(TimeButton.HeightProperty, this.ItemHeight);
                timeButton.SetValue(TimeButton.IsEnabledProperty, false);
                timeButton.SetValue(TimeButton.IsSelectedProperty, false);
                list.Add(timeButton);
            }
        }