This question is locked. New answers and comments are not allowed.
I'm writing a control that allows users to choose a departure (think flights or trains...).
Since different days have different departure times, I'd like the (right-hand) time-of-day panel to show a different list of times, depending on the day chosen in the (left-hand) date picker panel.
I try doing this by changing the ClockItemsSource property whenever the selected day changes.
But no matter how I do this, I can't get the time-of-day panel to change (it keeps being empty)!
Here's my (simplified) XAML:
Here's my code-behind:
I'm hoping someone can point me in the right direction...
/Thomas
Since different days have different departure times, I'd like the (right-hand) time-of-day panel to show a different list of times, depending on the day chosen in the (left-hand) date picker panel.
I try doing this by changing the ClockItemsSource property whenever the selected day changes.
But no matter how I do this, I can't get the time-of-day panel to change (it keeps being empty)!
Here's my (simplified) XAML:
public partial class DeparturePicker : UserControl{ private readonly ObservableCollection<TimeSpan> clockItems = new ObservableCollection<TimeSpan>(); public DeparturePicker() { InitializeComponent(); DateTimepicker.ClockItemsSource = clockItems; DateTimepicker.SelectionChanged += new Telerik.Windows.Controls.SelectionChangedEventHandler(DateTimepicker_SelectionChanged); } private DateTime? selectedDeparture = null; void DateTimepicker_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e) { if (selectedDeparture == DateTimepicker.SelectedValue) return; selectedDeparture = DateTimepicker.SelectedValue; //DateTimepicker.ClockItemsSource = GetDeparturesOnDay(selectedDeparture); // OK, the above didn't work - let's try this: this.clockItems.Clear(); foreach (var departure in GetDeparturesOnDay(selectedDeparture)) this.clockItems.Add(departure); } private IEnumerable<TimeSpan> GetDeparturesOnDay(DateTime? day) { IEnumerable<TimeSpan> result = new ObservableCollection<TimeSpan>() { new TimeSpan(9,0,0), new TimeSpan(10,0,0), new TimeSpan(10,5,0), new TimeSpan(10,22,0), new TimeSpan(13,15,0) }; return result; }}Here's my code-behind:
public partial class DeparturePicker : UserControl{ private readonly ObservableCollection<TimeSpan> clockItems = new ObservableCollection<TimeSpan>(); public DeparturePicker() { InitializeComponent(); DateTimepicker.ClockItemsSource = clockItems; DateTimepicker.SelectionChanged += new Telerik.Windows.Controls.SelectionChangedEventHandler(DateTimepicker_SelectionChanged); } private DateTime? selectedDeparture = null; void DateTimepicker_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e) { if (selectedDeparture == DateTimepicker.SelectedValue) return; selectedDeparture = DateTimepicker.SelectedValue; //DateTimepicker.ClockItemsSource = GetDeparturesOnDay(selectedDeparture); // OK, the above didn't work - let's try this: this.clockItems.Clear(); foreach (var departure in GetDeparturesOnDay(selectedDeparture)) this.clockItems.Add(departure); } private IEnumerable<TimeSpan> GetDeparturesOnDay(DateTime? day) { IEnumerable<TimeSpan> result = new ObservableCollection<TimeSpan>() { new TimeSpan(9,0,0), new TimeSpan(10,0,0), new TimeSpan(10,5,0), new TimeSpan(10,22,0), new TimeSpan(13,15,0) }; return result; }}I'm hoping someone can point me in the right direction...
/Thomas