This is a migrated thread and some comments may be shown as answers.

Dynamic ClockItemsSource?

5 Answers 100 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Thomas
Top achievements
Rank 1
Thomas asked on 20 Jan 2012, 01:43 PM
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:
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

5 Answers, 1 is accepted

Sort by
0
Thomas
Top achievements
Rank 1
answered on 20 Jan 2012, 01:44 PM
Sorry, the XAML is here:
<UserControl x:Class="Dfds.InfoBridge.UI.Views.Controls.UnitTracking.DeparturePicker"
    mc:Ignorable="d"
    d:DesignHeight="25" d:DesignWidth="100">
     
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadDateTimePicker x:Name="DateTimepicker"/>
    </Grid>
</UserControl>
0
Thomas
Top achievements
Rank 1
answered on 01 Feb 2012, 01:30 PM
Hi Telerik,

Can you help me with this? Please let me know if my question is not clear...
0
Boyan
Telerik team
answered on 06 Feb 2012, 01:50 PM
Hello,

I managed to reproduce the bad behavior. The RadDateTimePicker ClockItemsSource is changed but the layout is not updated. This is a bug in our control. I have logged the issue in our PITS and you can follow its progress here.

We will try to fix this ASAP in order for it to be included in Q1 which is due in the next few weeks.

Please, excuse us for the inconvenience. We have added points to your account for the report. Don't hesitate to contact us if you have other questions.


Regards,
Boyan
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Marcel
Top achievements
Rank 1
answered on 04 Sep 2012, 09:16 AM
Any info on when this bug will be fixed since it was reported 7 months ago?

I'm encountering the same problem as the topic starter.

Some background info:
The reason I'm dynamically updating the ClockItemsSource is because I want to define the range of times the user can select.
Using StartTime and EndTime is NOT an option, since there seems to be a bug in that as well. If I use an EndTime that is smaller than the StartTime, which means the EndTime is the day after the StartTime, the control just displays the times for the entire day. What I want is to show the times from the StartTime untill the EndTime. Because of this behaviour I have to do it manually, however this bug shows up in it's place..
0
Boyan
Telerik team
answered on 06 Sep 2012, 04:19 PM
Hi Marcel,

This bug is still pending and most probably will be scheduled for the service pack of Q3. However even with this working you will not be able to achieve the desired functionality as the Clock doesn't support showing hours from different dates. So when select 6th of September and then select 3:00 on the next day the selected date in the RadDateTimePicker will be 3:00 6th of September instead of 7th of September.

Greetings,
Boyan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DateTimePicker
Asked by
Thomas
Top achievements
Rank 1
Answers by
Thomas
Top achievements
Rank 1
Boyan
Telerik team
Marcel
Top achievements
Rank 1
Share this question
or