/// <summary> /// Generates the labels. /// </summary> private void GenerateLabels() { Action <UIElement> removeHandler = element => { Button b = element as Button; if (b != null) { b.Click -= OnLabelClicked; } }; // create the hour labels. These are not based on interval. if (HoursContainer != null) { HoursContainer.Children.ForEach(removeHandler); HoursContainer.Children.Clear(); EnumerableExtensions.Range(22, 0, 2) .ForEach(hour => HoursContainer.Children.Add( CreateLabelElement( ActualTimeGlobalizationInfo.FormatTime( DateTime.MinValue.AddHours(hour), ActualFormat, 'h', 'H', 't', ' '), TimeSpan.FromHours(hour)))); } // create the hour labels. These are not based on interval. if (MinutesContainer != null) { MinutesContainer.Children.ForEach(removeHandler); MinutesContainer.Children.Clear(); EnumerableExtensions.Range(55, 0, 5) .ForEach(minute => MinutesContainer.Children.Add( CreateLabelElement( ActualTimeGlobalizationInfo.FormatTime( DateTime.MinValue.AddMinutes(minute), new CustomTimeFormat("mm")), TimeSpan.FromMinutes(minute)))); } // create the hour labels. These are not based on interval. if (SecondsContainer != null) { SecondsContainer.Children.ForEach(removeHandler); SecondsContainer.Children.Clear(); EnumerableExtensions.Range(55, 0, 5) .ForEach(second => SecondsContainer.Children.Add( CreateLabelElement( ActualTimeGlobalizationInfo.FormatTime( DateTime.MinValue.AddSeconds(second), new CustomTimeFormat("ss")), TimeSpan.FromSeconds(second)))); } UpdateLayout(); LayoutLabels(); SetEnabledStatusOnLabels(); }
/// <summary> /// Regenerates the time items. /// </summary> private void RegenerateTimeItems() { TimeItemsSelection.Items.Clear(); // validate if (PopupMinutesInterval == 0) { // do not allow a zero interval. return; } DateTime runningTime = Value.HasValue ? Value.Value.Date : new DateTime(1900, 1, 1); DateTime startTime = Minimum.HasValue ? runningTime.Add(Minimum.Value.TimeOfDay) : runningTime; DateTime endTime = Maximum.HasValue ? runningTime.Add(Maximum.Value.TimeOfDay) : runningTime.AddDays(1).Subtract(TimeSpan.FromMilliseconds(1)); // ListTimePickerPopup will disregard seconds. TimeSpan increment = new TimeSpan(0, 0, PopupMinutesInterval, 0); while (runningTime <= endTime) { if (runningTime >= startTime) { TimeItemsSelection.Items.Add(new KeyValuePair <string, DateTime?>(ActualTimeGlobalizationInfo.FormatTime(runningTime, ActualFormat), runningTime)); } runningTime += increment; } }